| … | |
… | |
| 8 | =cut |
8 | =cut |
| 9 | |
9 | |
| 10 | use strict; |
10 | use strict; |
| 11 | use warnings; |
11 | use warnings; |
| 12 | use CGI qw(); |
12 | use CGI qw(); |
|
|
13 | use HTML::Entities; |
| 13 | |
14 | |
| 14 | sub initialize { |
15 | sub initialize { |
| 15 | my ($self) = @_; |
16 | my ($self) = @_; |
| 16 | my $r = $self->{r}; |
17 | my $r = $self->{r}; |
| 17 | my $db = $self->{db}; |
18 | my $db = $self->{db}; |
| … | |
… | |
| 31 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
32 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
| 32 | |
33 | |
| 33 | my $action = $r->param('action'); |
34 | my $action = $r->param('action'); |
| 34 | my $openfilename = $r->param('openfilename'); |
35 | my $openfilename = $r->param('openfilename'); |
| 35 | my $savefilename = $r->param('savefilename'); |
36 | my $savefilename = $r->param('savefilename'); |
| 36 | #FIXME get these values |
37 | |
|
|
38 | |
|
|
39 | #FIXME get these values from global course environment (see subroutines as well) |
| 37 | my $default_msg = 'default.msg'; |
40 | my $default_msg_file = 'default.msg'; |
| 38 | my $old_default_msg = 'old_default.msg'; |
41 | my $old_default_msg_file = 'old_default.msg'; |
|
|
42 | |
|
|
43 | # store data |
| 39 | my $defaultFrom = 'FIXME from'; |
44 | $self->{defaultFrom} = 'FIXME from'; |
| 40 | my $defaultReply = 'FIXME reply'; |
45 | $self->{defaultReply} = 'FIXME reply'; |
|
|
46 | $self->{rows} = (defined($r->param('rows'))) ? $r->param('rows') : $ce->{mail}->{editor_window_rows}; |
|
|
47 | $self->{columns} = (defined($r->param('columns'))) ? $r->param('columns') : $ce->{mail}->{editor_window_columns}; |
|
|
48 | $self->{default_msg_file} = $default_msg_file; |
|
|
49 | $self->{old_default_msg_file} = $old_default_msg_file; |
| 41 | ############################################################################################# |
50 | ################################################################# |
| 42 | # Get directory file name |
51 | # Check the validity of the input file name |
| 43 | ############################################################################################# |
52 | ################################################################# |
| 44 | |
53 | my $input_file = ''; |
| 45 | #make sure message file was submitted and exists |
54 | #make sure an input message file was submitted and exists |
| 46 | my $messageFileName; |
55 | #else use the default message |
|
|
56 | if ( defined($openfilename) ) { |
| 47 | if (defined($openfilename) && -e "${emailDirectory}$openfilename") { |
57 | if ( -e "${emailDirectory}/$openfilename") { |
| 48 | if ( -R "${emailDirectory}$openfilename") { |
58 | if ( -R "${emailDirectory}/$openfilename") { |
| 49 | $messageFileName = $openfilename; |
59 | $input_file = $openfilename; |
| 50 | } else { |
60 | } else { |
|
|
61 | warn join("", |
| 51 | warn "The file ${emailDirectory}$openfilename is not readable by the webserver. |
62 | "The file ${emailDirectory}/$openfilename is not readable by the webserver.",CGI::br(), |
| 52 | Check that it's permissions are set correctly."; |
63 | "Check that it's permissions are set correctly.", |
|
|
64 | ); |
| 53 | } |
65 | } |
| 54 | } else { |
66 | } else { |
| 55 | $messageFileName = $default_msg; |
67 | $input_file = $default_msg_file; |
|
|
68 | warn join("", |
|
|
69 | "The file ${emailDirectory}/$openfilename cannot be found.",CGI::br(), |
|
|
70 | "Check whether it exists and whether the directory $emailDirectory can be read by the webserver.",CGI::br(), |
|
|
71 | "Using contents of the default message $default_msg_file instead.", |
|
|
72 | ); |
| 56 | } |
73 | } |
|
|
74 | } else { |
|
|
75 | $input_file = $default_msg_file; |
|
|
76 | } |
|
|
77 | $self->{input_file}=$input_file; |
|
|
78 | |
|
|
79 | ################################################################# |
|
|
80 | # Determine the file name to save message into |
|
|
81 | ################################################################# |
|
|
82 | my $output_file = ''; |
|
|
83 | if (defined($action) and $action eq 'Save as Default') { |
|
|
84 | $output_file = $default_msg_file; |
|
|
85 | } elsif ( defined($savefilename) ){ |
|
|
86 | $output_file = $savefilename; |
|
|
87 | } elsif ( defined($input_file) ) { |
|
|
88 | $output_file = $input_file; |
|
|
89 | } |
|
|
90 | |
|
|
91 | ################################################################# |
|
|
92 | # Sanity check on save file name |
|
|
93 | ################################################################# |
|
|
94 | |
|
|
95 | if ($output_file =~ /^[~.]/ || $output_file =~ /\.\./) { |
|
|
96 | $self->submission_error("For security reasons, you cannot specify a merge file from a directory |
|
|
97 | higher than the email directory (you can't use ../blah/blah). |
|
|
98 | Please specify a different file or move the needed file to the email directory"); |
|
|
99 | } |
|
|
100 | |
|
|
101 | $self->{output_file} = $output_file; |
|
|
102 | # FIXME $output_file can be blank if there was no savefilename |
|
|
103 | |
|
|
104 | ############################################################################################# |
|
|
105 | # Determine input source |
|
|
106 | ############################################################################################# |
|
|
107 | my $input_source = ( defined( $r->param('body') ) and $action ne 'Open' ) ? 'form' : 'file'; |
|
|
108 | # warn "FIXME input source is $input_source from $input_file"; |
|
|
109 | ############################################################################################# |
|
|
110 | # Get inputs |
|
|
111 | ############################################################################################# |
|
|
112 | my($from, $replyTo, $r_text, $subject); |
|
|
113 | if ($input_source eq 'file') { |
|
|
114 | |
|
|
115 | ($from, $replyTo,$subject,$r_text) = $self->read_input_file("$emailDirectory/$input_file"); |
|
|
116 | |
|
|
117 | } elsif ($input_source eq 'form') { |
|
|
118 | # read info from the form |
|
|
119 | # bail if there is no message body |
| 57 | |
120 | |
| 58 | $self->{messageFileName}=$messageFileName; |
121 | $from = $r->param('from'); |
| 59 | |
122 | $replyTo = $r->param('replyTo'); |
| 60 | # make sure that the file path is legal (lies below inside the email directory |
123 | $subject = $r->param('subject'); |
| 61 | if (defined($savefilename) && ($savefilename =~ /^[~.]/ or $savefilename =~ /\.\./ ) ){ |
124 | my $body = $r->param('body'); |
| 62 | $self->fatal_error("For security reasons, you cannot save a message", |
125 | # Sanity check: body must contain non-white space |
| 63 | "in any directory higher than the email directory.", |
126 | $self->submission_error('You didn\'t enter any message.') unless ($r->param('body') =~ /\S/); |
| 64 | "Please specify a file name to save under."); |
127 | $r_text = \$body; |
|
|
128 | |
| 65 | } |
129 | } |
|
|
130 | # store data |
|
|
131 | $self->{from} = $from; |
|
|
132 | $self->{replyTo} = $replyTo; |
|
|
133 | $self->{subject} = $subject; |
|
|
134 | $self->{r_text} = $r_text; |
|
|
135 | |
| 66 | |
136 | |
| 67 | ############################################################################################# |
137 | ############################################################################################# |
| 68 | # if no form is submitted gather data from default message file and return |
138 | # if no form is submitted, gather data needed to produce the mail form and return |
| 69 | ############################################################################################# |
139 | ############################################################################################# |
| 70 | |
140 | |
| 71 | unless (defined($action) ){ |
141 | if(not defined($action) or $action eq 'Open' or $action eq 'Resize message window' ){ |
| 72 | ############################################################################################# |
142 | # warn "FIXME action is |$action| no further initialization required"; |
| 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 ''; |
143 | return ''; |
| 113 | } |
144 | } |
| 114 | |
145 | |
| 115 | |
146 | |
| 116 | |
147 | |
| 117 | |
148 | |
| 118 | |
149 | |
| 119 | ############################################################################################# |
150 | ############################################################################################# |
| 120 | # If form is submitted deal with filled out forms |
151 | # If form is submitted deal with filled out forms |
| 121 | # and various actions resulting from different buttons |
152 | # and various actions resulting from different buttons |
| 122 | ############################################################################################# |
153 | ############################################################################################# |
| 123 | |
154 | |
| 124 | my $from = $r->param('from'); |
155 | |
| 125 | my $to = $r->param('To'); |
156 | my $to = $r->param('To'); |
| 126 | my $replyTo = $r->param('replyTo'); |
157 | |
| 127 | my $subject = $r->param('subject'); |
158 | |
| 128 | my $body = $r->param('body'); |
|
|
| 129 | |
159 | |
| 130 | |
160 | ################################################################################### |
| 131 | |
161 | #Determine the appropriate script action from the buttons |
| 132 | # script action |
162 | ################################################################################### |
|
|
163 | # save actions |
|
|
164 | # "save" button |
|
|
165 | # "save as" button |
|
|
166 | # "save as default" button |
|
|
167 | # preview actions |
|
|
168 | # 'preview' button |
|
|
169 | # email actions |
|
|
170 | # 'entire class' |
|
|
171 | # 'selected studentIDs' |
|
|
172 | # option actions |
|
|
173 | # 'reset rows' |
|
|
174 | # error actions (various) |
|
|
175 | |
| 133 | my $script_action = ''; |
176 | my $script_action = ''; |
| 134 | # user_errors |
177 | # user_errors |
| 135 | # save |
178 | # save |
| 136 | # save as |
179 | # save as |
| 137 | # save as default |
180 | # save as default |
| 138 | # send mail |
181 | # send mail |
| 139 | # set defaults |
182 | # set defaults |
| 140 | |
183 | |
|
|
184 | if ($action eq 'Save' or $action eq 'Save as:' or $action eq 'Save as Default') { |
|
|
185 | |
|
|
186 | # warn "FIXME Saving files action = $action outputFileName=$output_file"; |
| 141 | |
187 | |
|
|
188 | ################################################################# |
|
|
189 | # construct message body |
|
|
190 | ################################################################# |
|
|
191 | my $temp_body = ${ $r_text }; |
|
|
192 | $temp_body =~ s/\r\n/\n/g; |
|
|
193 | $temp_body = join("", |
|
|
194 | "From: $from \nReply-To: $replyTo\n" , |
|
|
195 | "Subject: $subject\n" , |
|
|
196 | "Message: \n $temp_body"); |
|
|
197 | # warn "FIXME from $from | subject $subject |reply $replyTo|msg $temp_body"; |
|
|
198 | ################################################################# |
|
|
199 | # overwrite protection |
|
|
200 | ################################################################# |
|
|
201 | if ($action eq 'Save as:' and -e "$emailDirectory/$output_file") { |
|
|
202 | $self->submission_error("The file $emailDirectory/$output_file already exists and cannot be overwritten"); |
|
|
203 | return; |
|
|
204 | } |
|
|
205 | |
|
|
206 | ################################################################# |
|
|
207 | # Back up existing file? |
|
|
208 | ################################################################# |
|
|
209 | if ($action eq 'Save as Default') { |
|
|
210 | warn "FIXME backup existing default file"; |
|
|
211 | } |
|
|
212 | ################################################################# |
|
|
213 | # Save the message |
|
|
214 | ################################################################# |
|
|
215 | $self->saveProblem($temp_body, "${emailDirectory}/$output_file" ); |
|
|
216 | $self->{message} = "Message saved to file ${emailDirectory}/$output_file"; |
|
|
217 | # warn "FIXME saving to ${emailDirectory}/$output_file"; |
|
|
218 | } elsif ($action eq 'preview') { |
|
|
219 | |
|
|
220 | |
|
|
221 | } elsif ($action eq 'Send Email') { |
|
|
222 | |
|
|
223 | |
|
|
224 | |
|
|
225 | |
|
|
226 | } else { |
|
|
227 | warn "Don't recognize button $action"; |
|
|
228 | } |
| 142 | |
229 | |
| 143 | #if Save button was clicked |
230 | #if Save button was clicked |
| 144 | if (( $r->param('action') eq 'Save') && defined($r->param('body')) && defined($r->param('savefilename'))) { |
231 | if (( $r->param('action') eq 'Save') && defined($r->param('body')) && defined($r->param('savefilename'))) { |
| 145 | |
232 | |
| 146 | my $temp_body = $body; |
233 | # my $temp_body = $body; |
| 147 | $temp_body =~ s/\r\n/\n/g; |
234 | # $temp_body =~ s/\r\n/\n/g; |
| 148 | $temp_body = "From: " . $from . "\n" . |
235 | # $temp_body = "From: " . $from . "\n" . |
| 149 | "Reply-To: " . $replyTo . "\n" . |
236 | # "Reply-To: " . $replyTo . "\n" . |
| 150 | "Subject: " . $subject . "\n" . |
237 | # "Subject: " . $subject . "\n" . |
| 151 | "Message: \n" . $temp_body; |
238 | # "Message: \n" . $temp_body; |
| 152 | |
239 | # |
| 153 | saveProblem($temp_body, $savefilename); |
240 | # saveProblem($temp_body, $savefilename); |
| 154 | $messageFileName = $savefilename; |
241 | # $messageFileName = $savefilename; |
| 155 | |
242 | |
| 156 | #if Save As button was clicked |
243 | #if Save As button was clicked |
| 157 | } elsif (( $r->param('action') eq 'Save as') && defined($r->param('body')) && defined($r->param('savefilename'))) { |
244 | } elsif (( $r->param('action') eq 'Save as:') && defined($r->param('body')) && defined($r->param('savefilename'))) { |
| 158 | |
245 | |
| 159 | $messageFileName = $savefilename; |
246 | # $messageFileName = $savefilename; |
| 160 | |
247 | # |
| 161 | if ($messageFileName =~ /^[~.]/ || $messageFileName =~ /\.\./) { |
248 | # 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"); |
249 | # $self->submission_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 | } |
250 | # } |
| 164 | |
251 | # |
| 165 | |
252 | # |
| 166 | my $temp_body = $body; |
253 | # my $temp_body = $body; |
| 167 | $temp_body =~ s/\r\n/\n/g; |
254 | # $temp_body =~ s/\r\n/\n/g; |
| 168 | $temp_body = join("", |
255 | # $temp_body = join("", |
| 169 | "From: $from \nReply-To: $replyTo)\n" , |
256 | # "From: $from \nReply-To: $replyTo)\n" , |
| 170 | "Subject: $subject\n" , |
257 | # "Subject: $subject\n" , |
| 171 | "Message: \n $temp_body"); |
258 | # "Message: \n $temp_body"); |
| 172 | |
259 | # |
| 173 | saveNewProblem($temp_body, $messageFileName); |
260 | # saveNewProblem($temp_body, $messageFileName); |
| 174 | |
261 | |
| 175 | #if Save As Default button was clicked |
262 | #if Save As Default button was clicked |
| 176 | } elsif (( $r->param('action') eq 'Save as Default') && defined($r->param('body'))) { |
263 | } elsif (( $r->param('action') eq 'save_as_default') && defined($r->param('body'))) { |
| 177 | |
264 | |
| 178 | my $temp_body; |
265 | # my $temp_body; |
| 179 | $temp_body = $r->param('body'); |
266 | # $temp_body = $r->param('body'); |
| 180 | $temp_body =~ s/\r\n/\n/g; |
267 | # $temp_body =~ s/\r\n/\n/g; |
| 181 | |
268 | # |
| 182 | #get default.msg and back it up in default.old.msg |
269 | # #get default.msg and back it up in default.old.msg |
| 183 | open DEFAULT, "$emailDirectory/$default_msg"; |
270 | # open DEFAULT, "$emailDirectory/$default_msg_file"; |
| 184 | $temp_body = <DEFAULT>; |
271 | # $temp_body = <DEFAULT>; |
| 185 | close DEFAULT; |
272 | # close DEFAULT; |
| 186 | |
273 | # |
| 187 | if ( -e "$emailDirectory/$old_default_msg") { |
274 | # if ( -e "$emailDirectory/$old_default_msg_file") { |
| 188 | # saveProblem($temp_body, $old_default_msg); |
275 | # # saveProblem($temp_body, $old_default_msg_file); |
| 189 | } else { |
276 | # } else { |
| 190 | # saveNewProblem($temp_body, $old_default_msg); |
277 | # # saveNewProblem($temp_body, $old_default_msg_file); |
| 191 | } |
278 | # } |
| 192 | |
279 | # |
| 193 | #save new default message as default.msg |
280 | # #save new default message as default.msg |
| 194 | $temp_body = $body; |
281 | # $temp_body = $body; |
| 195 | $temp_body =~ s/\r\n/\n/g; |
282 | # $temp_body =~ s/\r\n/\n/g; |
| 196 | $temp_body = join("", |
283 | # $temp_body = join("", |
| 197 | "From: $from \nReply-To: $replyTo)\n" , |
284 | # "From: $from \nReply-To: $replyTo)\n" , |
| 198 | "Subject: $subject\n" , |
285 | # "Subject: $subject\n" , |
| 199 | "Message: \n $temp_body"); |
286 | # "Message: \n $temp_body"); |
| 200 | |
287 | # |
| 201 | # saveProblem($temp_body, $default_msg); |
288 | # # saveProblem($temp_body, $default_msg_file); |
| 202 | $messageFileName = $default_msg; |
289 | # $messageFileName = $default_msg_file; |
| 203 | |
290 | |
| 204 | #if Send Email button was clicked |
291 | #if Send Email button was clicked |
| 205 | } elsif ( $r->param('action') eq 'Send Email' ) { |
292 | } elsif ( $r->param('action') eq 'Send Email' ) { |
| 206 | |
293 | |
| 207 | my @studentID = (); |
294 | my @studentID = (); |
| … | |
… | |
| 267 | # $status{$studentID} = CL_getStudentStatus($login_name); |
354 | # $status{$studentID} = CL_getStudentStatus($login_name); |
| 268 | # $email{$studentID} = CL_getStudentEmailAddress($login_name); |
355 | # $email{$studentID} = CL_getStudentEmailAddress($login_name); |
| 269 | # $login{$studentID} = $login_name; |
356 | # $login{$studentID} = $login_name; |
| 270 | # } |
357 | # } |
| 271 | } else { |
358 | } 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.'); |
359 | $self->submission_error('You didn\'t select any recipients. Make sure you select either all student in the course, individual students or a whole classlist.'); |
| 273 | } |
360 | } |
| 274 | |
361 | |
| 275 | my $mergeFile = ''; |
362 | my $mergeFile = ''; |
| 276 | |
363 | |
| 277 | #the radio button named 'merge' determines whether to take the selected mergefile |
364 | #the radio button named 'merge' determines whether to take the selected mergefile |
| … | |
… | |
| 281 | |
368 | |
| 282 | $mergeFile = $templateDirectory . $r->param('mergeFile') |
369 | $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 / |
370 | if ($r->param('merge') eq 'mergeFile' && defined($r->param('mergeFile')) && $r->param('mergeFile') !~ m|/$|); #does not end in a / |
| 284 | |
371 | |
| 285 | if ($mergeFile =~ /^[~.]/ || $mergeFile =~ /\.\./) { |
372 | 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"); |
373 | $self->submission_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 | } |
374 | } |
| 288 | if ($r->param('body') =~ /(\$COL\[.*?\])/ && !(-e $mergeFile)) { |
375 | 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."); |
376 | $self->submission_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 | } |
377 | } |
| 291 | |
378 | |
| 292 | |
379 | |
| 293 | my %mergeAArray = (); |
380 | my %mergeAArray = (); |
| 294 | # unless ($mergeFile eq '') {%mergeAArray = &delim2aa($mergeFile);} |
381 | # unless ($mergeFile eq '') {%mergeAArray = &delim2aa($mergeFile);} |
| 295 | # |
382 | # |
| 296 | $self->fatal_error('You didn\'t enter any message.') if ($r->param('body') eq ''); |
383 | |
| 297 | # |
384 | # |
| 298 | # foreach my $studentID (@studentID) { |
385 | # foreach my $studentID (@studentID) { |
| 299 | # @COL =(); |
386 | # @COL =(); |
| 300 | # $SID = $studentID; |
387 | # $SID = $studentID; |
| 301 | # $LN = defined $ln{$studentID} ? $ln{$studentID} :''; |
388 | # $LN = defined $ln{$studentID} ? $ln{$studentID} :''; |
| … | |
… | |
| 546 | my $from = $self->{from}; |
633 | my $from = $self->{from}; |
| 547 | my $subject = $self->{subject}; |
634 | my $subject = $self->{subject}; |
| 548 | my $replyTo = $self->{replyTo}; |
635 | my $replyTo = $self->{replyTo}; |
| 549 | my $columns = $self->{columns}; |
636 | my $columns = $self->{columns}; |
| 550 | my $rows = $self->{rows}; |
637 | my $rows = $self->{rows}; |
| 551 | my $text = defined($self->{r_text}) ? ${ $self->{r_text} }: 'FIXME'; |
638 | my $text = defined($self->{r_text}) ? ${ $self->{r_text} }: 'FIXME no text was produced by initialization!!'; |
| 552 | my $messageFileName = $self->{messageFileName}; |
639 | my $input_file = $self->{input_file}; |
|
|
640 | my $output_file = $self->{output_file}; |
| 553 | |
641 | |
| 554 | CGI::popup_menu(-name=>'classList', |
642 | CGI::popup_menu(-name=>'classList', |
| 555 | -values=>\@users, |
643 | -values=>\@users, |
| 556 | -labels=>\%classlistLabels, |
644 | -labels=>\%classlistLabels, |
| 557 | -size => 10, |
645 | -size => 10, |
| … | |
… | |
| 561 | print CGI::start_form({method=>"post", action=>$r->uri()}); |
649 | print CGI::start_form({method=>"post", action=>$r->uri()}); |
| 562 | #create list of sudents |
650 | #create list of sudents |
| 563 | # show professors's name and email address |
651 | # show professors's name and email address |
| 564 | # show replyTo field and From field |
652 | # show replyTo field and From field |
| 565 | print CGI::start_table({-border=>'2', -cellpadding=>'4'}); |
653 | print CGI::start_table({-border=>'2', -cellpadding=>'4'}); |
| 566 | print CGI::Tr({-align=>'left',-valign=>'VCENTER'}, |
654 | print CGI::Tr({-align=>'left',-valign=>'VCENTER'}, |
| 567 | CGI::td("\n", CGI::p( CGI::b('From: '), CGI::br(), CGI::textfield(-name=>"from", -size=>30, -value=>$from, -override=>1), ), |
655 | CGI::td("Input file: $input_file","\n",CGI::br(), |
|
|
656 | CGI::submit(-name=>'action', -value=>'open',-label=>'Open'), "\n", |
|
|
657 | CGI::textfield(-name=>'openfilename', -size => 20, -value=> "$input_file", -override=>1), "\n",CGI::br(), |
|
|
658 | "Output file: $output_file","\n",CGI::br(), |
|
|
659 | "\n", 'From:',' ', CGI::textfield(-name=>"from", -size=>30, -value=>$from, -override=>1), |
| 568 | "\n", CGI::p( CGI::b('Reply-To: '), CGI::br(), CGI::textfield(-name=>"replyTo", -size=>30, -value=>$replyTo, -override=>1), ), |
660 | "\n", CGI::br(),'Reply-To: ', CGI::textfield(-name=>"replyTo", -size=>30, -value=>$replyTo, -override=>1), |
| 569 | "\n", CGI::p( CGI::b('Subject: '), CGI::br(), CGI::textarea(-name=>'subject', -default=>$subject, -rows=>2,-columns=>30, -override=>1), ), |
661 | "\n", CGI::br(),'Subject: ', CGI::br(), CGI::textarea(-name=>'subject', -default=>$subject, -rows=>3,-columns=>40, -override=>1), |
| 570 | ), |
662 | ), |
| 571 | CGI::td({-align=>'left'}, |
663 | CGI::td({-align=>'left'}, |
| 572 | CGI::radio_group(-name=>'radio', -values=>['all_students','studentID'], |
664 | CGI::radio_group(-name=>'radio', -values=>['all_students','studentID'], |
| 573 | -labels=>{all_students=>'All active students',studentID => 'Select recipients'}, |
665 | -labels=>{all_students=>'All active students',studentID => 'Select recipients'}, |
| 574 | -default=>'studentID', |
666 | -default=>'studentID', |
| 575 | -linebreak=>1), |
667 | -linebreak=>1), |
| 576 | CGI::br(), |
668 | CGI::br(), |
|
|
669 | CGI::popup_menu(-name=>'classList', |
|
|
670 | -values=>\@users, |
|
|
671 | -labels=>\%classlistLabels, |
|
|
672 | -size => 10, |
|
|
673 | -multiple => 1, |
|
|
674 | -default=>'Yourself' |
|
|
675 | ), |
|
|
676 | |
|
|
677 | |
|
|
678 | ), |
|
|
679 | CGI::td({align=>'left'}, |
|
|
680 | CGI::submit(-name=>'preview', -value=>'preview',-label=>'Preview')," email to ", |
| 577 | CGI::popup_menu(-name=>'classList', |
681 | CGI::popup_menu(-name=>'classList', |
| 578 | -values=>\@users, |
682 | -values=>\@users, |
| 579 | -labels=>\%classlistLabels, |
683 | -labels=>\%classlistLabels, |
| 580 | -size => 10, |
|
|
| 581 | -multiple => 1, |
|
|
| 582 | -default=>'Yourself' |
684 | -default=>'Yourself' |
| 583 | ), |
685 | ), |
| 584 | |
|
|
| 585 | |
|
|
| 586 | ), |
|
|
| 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(), |
686 | CGI::br(),CGI::br(), |
| 595 | CGI::submit(-name=>'action', -value=>'Revert to original and Resize message window'),CGI::br(), |
687 | CGI::submit(-name=>'action', -value=>'resize', -label=>'Resize message window'),CGI::br(), |
| 596 | " Rows: ", CGI::textfield(-name=>'rows', -size=>3, -value=>$rows), |
688 | " Rows: ", CGI::textfield(-name=>'rows', -size=>3, -value=>$rows), |
| 597 | " Columns: ", CGI::textfield(-name=>'columns', -size=>3, -value=>$columns), |
689 | " 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(), |
690 | CGI::br(),CGI::br(), |
| 601 | #show available macros |
691 | #show available macros |
| 602 | CGI::popup_menu( |
692 | CGI::popup_menu( |
| 603 | -name=>'dummyName', |
693 | -name=>'dummyName', |
| 604 | -values=>['', '$SID', '$FN', '$LN', '$SECTION', '$RECITATION','$STATUS', '$EMAIL', '$LOGIN', '$COL[3]', '$COL[-1]'], |
694 | -values=>['', '$SID', '$FN', '$LN', '$SECTION', '$RECITATION','$STATUS', '$EMAIL', '$LOGIN', '$COL[3]', '$COL[-1]'], |
| 605 | -labels=>{''=>'list of insertable macros', |
695 | -labels=>{''=>'list of insertable macros', |
| 606 | '$SID'=>'$SID - Student ID', |
696 | '$SID'=>'$SID - Student ID', |
| 607 | '$FN'=>'$FN - First name', |
697 | '$FN'=>'$FN - First name', |
| 608 | '$LN'=>'$LN - Last name', |
698 | '$LN'=>'$LN - Last name', |
| 609 | '$SECTION'=>'$SECTION - Student\'s Section', |
699 | '$SECTION'=>'$SECTION - Student\'s Section', |
| 610 | '$RECITATION'=>'$RECITATION', |
700 | '$RECITATION'=>'$RECITATION', |
| 611 | '$STATUS'=>'$STATUS - C, Audit, Drop, etc.', |
701 | '$STATUS'=>'$STATUS - C, Audit, Drop, etc.', |
| 612 | '$EMAIL'=>'$EMAIL - Email address', |
702 | '$EMAIL'=>'$EMAIL - Email address', |
| 613 | '$LOGIN'=>'$LOGIN - Login', |
703 | '$LOGIN'=>'$LOGIN - Login', |
| 614 | '$COL[3]'=>'$COL[3] - 3rd column in merge file', |
704 | '$COL[3]'=>'$COL[3] - 3rd column in merge file', |
| 615 | '$COL[-1]'=>'$COL[-1] - Last column' |
705 | '$COL[-1]'=>'$COL[-1] - Last column' |
| 616 | } |
706 | } |
| 617 | ), "\n", |
707 | ), "\n", |
| 618 | ), |
708 | ), |
| 619 | |
709 | |
| 620 | ); |
710 | ); # end Tr |
| 621 | print CGI::end_table(); |
711 | print CGI::end_table(); |
| 622 | #create a textbox with the subject and a textarea with the message |
712 | #create a textbox with the subject and a textarea with the message |
| 623 | |
713 | |
| 624 | #print actual body of message |
714 | #print actual body of message |
| 625 | |
715 | |
| 626 | |
716 | print "\n", CGI::p( $self->{message}) if defined($self->{message}); |
| 627 | print "\n", CGI::p( CGI::textarea(-name=>'body', -default=>$text, -rows=>$rows, -columns=>$columns, -override=>1)); |
717 | print "\n", CGI::p( CGI::textarea(-name=>'body', -default=>$text, -rows=>$rows, -columns=>$columns, -override=>1)); |
|
|
718 | |
| 628 | #create all necessary action buttons |
719 | #create all necessary action buttons |
| 629 | print CGI::p(CGI::submit(-name=>'action', -value=>'Open'), "\n", |
720 | print CGI::table( { -border=>2,-cellpadding=>4}, |
| 630 | CGI::textfield(-name=>'savefilename', -size => 20, -value=> "$messageFileName", -override=>1), ' ', |
721 | CGI::Tr( |
| 631 | CGI::submit(-name=>'action', -value=>'Save'), " \n", |
722 | CGI::td( CGI::submit(-name=>'action', -value=>'Send Email') ), "\n", |
|
|
723 | CGI::td(CGI::submit(-name=>'action', -value=>'Save')," to $output_file"), " \n", |
| 632 | CGI::submit(-name=>'action', -value=>'Save as'), " \n", |
724 | CGI::td(CGI::submit(-name=>'action', -value=>'Save as:'), |
|
|
725 | CGI::textfield(-name=>'savefilename', -size => 20, -value=> "$output_file", -override=>1) |
|
|
726 | ), "\n", |
| 633 | CGI::submit(-name=>'action', -value=>'Save as Default'), |
727 | CGI::td(CGI::submit(-name=>'action', -value=>'Save as Default')), |
| 634 | CGI::submit(-name=>'action', -value=>'Send Email'), "\n", CGI::br(), |
728 | ) |
| 635 | 'For "Save As" choose a new filename.', |
|
|
| 636 | ); |
729 | ); |
| 637 | |
730 | |
| 638 | ############################################################################################################## |
731 | ############################################################################################################## |
| 639 | |
732 | |
| 640 | print $self->hidden_authen_fields(); |
733 | print $self->hidden_authen_fields(); |
| 641 | print CGI::submit({name=>"save_classlist", value=>"Save Changes to Users"}); |
734 | # print CGI::submit({name=>"save_classlist", value=>"Save Changes to Users"}); |
| 642 | print CGI::end_form(); |
735 | print CGI::end_form(); |
| 643 | return ""; |
736 | return ""; |
| 644 | } |
737 | } |
| 645 | |
738 | |
| 646 | ############################################################################## |
739 | ############################################################################## |
| 647 | # Utility methods |
740 | # Utility methods |
| 648 | ############################################################################## |
741 | ############################################################################## |
| 649 | sub fatal_error { |
742 | sub submission_error { |
| 650 | my $self = shift; |
743 | my $self = shift; |
| 651 | my $msg = join " ", @_; |
744 | my $msg = join " ", @_; |
| 652 | # $cgi->start_html('-title' => 'User error'), |
745 | # $cgi->start_html('-title' => 'User error'), |
| 653 | # $cgi->h1('User error'), |
746 | # $cgi->h1('User error'), |
| 654 | # $cgi->p, |
747 | # $cgi->p, |
| … | |
… | |
| 657 | # "Please hit the "<B>Back</B>" button on your browser to ", |
750 | # "Please hit the "<B>Back</B>" button on your browser to ", |
| 658 | # "try again, or notify ", $cgi->br, |
751 | # "try again, or notify ", $cgi->br, |
| 659 | # "<", $cgi->a({href=>"mailto:$Global::webmaster"}, $Global::webmaster), "> ", |
752 | # "<", $cgi->a({href=>"mailto:$Global::webmaster"}, $Global::webmaster), "> ", |
| 660 | # "if you believe this message is in error.", |
753 | # "if you believe this message is in error.", |
| 661 | # $cgi->end_html; |
754 | # $cgi->end_html; |
| 662 | $self->{submitError}= CGI::b(HTML::Entities::encode($msg)). |
755 | $self->{submitError}= CGI::b(HTML::Entities::encode($msg)).CGI::br(). |
| 663 | qq{"Please hit the "<B>Back</B>" button on your browser to |
756 | qq{Please hit the "<B>Back</B>" button on your browser to |
| 664 | try again, or notify your web master |
757 | try again, or notify your web master |
| 665 | if you believe this message is in error. |
758 | if you believe this message is in error. |
| 666 | }; |
759 | }; |
| 667 | return; |
760 | return; |
| 668 | } |
761 | } |
| 669 | |
762 | |
|
|
763 | sub saveProblem { |
|
|
764 | my $self = shift; |
|
|
765 | my ($body, $probFileName)= @_; |
|
|
766 | local(*PROBLEM); |
|
|
767 | open (PROBLEM, ">$probFileName") || |
|
|
768 | $self->submission_error("Could not open $probFileName for writing. |
|
|
769 | Check that the permissions for this problem are 660 (-rw-rw----)"); |
|
|
770 | print PROBLEM $body; |
|
|
771 | close PROBLEM; |
|
|
772 | chmod 0660, "$probFileName" || |
|
|
773 | $self->submission_error(" |
|
|
774 | CAN'T CHANGE PERMISSIONS ON FILE $probFileName"); |
|
|
775 | } |
|
|
776 | |
|
|
777 | sub read_input_file { |
|
|
778 | my $self = shift; |
|
|
779 | my $filePath = shift; |
|
|
780 | my ($text, @text); |
|
|
781 | my $header = ''; |
|
|
782 | my ($subject, $from, $replyTo); |
|
|
783 | local(*FILE); |
|
|
784 | if (-e "$filePath") { |
|
|
785 | open FILE, "$filePath" || $self->submission_error("Can't open $filePath"); |
|
|
786 | while ($header !~ s/Message:\s*$//m) { |
|
|
787 | $header .= <FILE>; |
|
|
788 | } |
|
|
789 | $text = join( '', <FILE>); |
|
|
790 | $text =~ s/^\s*//; # remove initial white space if any. |
|
|
791 | $header =~ /^From:\s(.*)$/m; |
|
|
792 | $from = $1 or $from = $self->{defaultFrom}; |
|
|
793 | |
|
|
794 | $header =~ /^Reply-To:\s(.*)$/m; |
|
|
795 | $replyTo = $1 or $replyTo = $self->{defaultReply}; |
|
|
796 | |
|
|
797 | $header =~ /^Subject:\s(.*)$/m; |
|
|
798 | $subject = $1; |
|
|
799 | |
|
|
800 | } else { |
|
|
801 | $from = $self->{defaultFrom}; |
|
|
802 | $replyTo = $self->{defaultReply}; |
|
|
803 | $text = "FIXME file $filePath doesn't exist"; |
|
|
804 | $subject = "FIXME default subject"; |
|
|
805 | } |
|
|
806 | return ($from, $replyTo, $subject, \$text); |
|
|
807 | } |
| 670 | 1; |
808 | 1; |