Parent Directory
|
Revision Log
initial import
1 #!/usr/bin/perl 2 3 ## This file is profAddStudent.pl 4 ## It provides access to utilities for building problem sets 5 ## 6 7 #################################################################### 8 # Copyright @ 1995-1999 University of Rochester 9 # All Rights Reserved 10 #################################################################### 11 12 use lib '/ww/webwork/development/'; # mainWeBWorKDirectory; 13 14 use CGI qw(:standard); 15 use Global; 16 use Auth; 17 use strict; 18 use TimeLocal; 19 20 my $logTimingData = 0; 21 my $beginTime; 22 23 # begin Timing code 24 if ($logTimingData == 1) { 25 use Benchmark; 26 $beginTime = new Benchmark; 27 } 28 # end Timing code 29 30 31 32 my $cgi = new CGI; 33 my %inputs = $cgi->Vars(); 34 35 # get information from CGI inputs (see also below for additional information) 36 37 my $Course = $inputs{'course'}; 38 my $User = $inputs{'user'}; 39 my $Session_key = $inputs{'key'}; 40 41 # verify that information has been received 42 unless($Course && $User && $Session_key) { 43 &wwerror("$0","The script did not receive the proper input data.","",""); 44 } 45 46 # establish environment for this script 47 48 &Global::getCourseEnvironment($inputs{'course'}); 49 50 51 my $cgiURL = getWebworkCgiURL; 52 my $courseScriptsDirectory = getCourseScriptsDirectory; 53 my $databaseDirectory = getCourseDatabaseDirectory; 54 my $htmlURL = getCourseHtmlURL; 55 my $scriptDirectory = getWebworkScriptDirectory; 56 my $templateDirectory = getCourseTemplateDirectory; 57 my $dat = getDat; 58 my $dd = getDirDelim; 59 60 require "${scriptDirectory}$Global::DBglue_pl"; 61 require "${scriptDirectory}$Global::classlist_DBglue_pl"; 62 require "${scriptDirectory}$Global::FILE_pl"; 63 require "${scriptDirectory}HTMLglue.pl"; 64 require "${scriptDirectory}$Global::buildProbSetTools"; 65 66 # log access 67 &Global::log_info('', query_string); 68 69 my $passwordFile = &Global::getCoursePasswordFile($inputs{'course'}); 70 my $permissionsFile = &Global::getCoursePermissionsFile($inputs{'course'}); 71 my $permissions = &get_permissions($inputs{'user'}, $permissionsFile); 72 my $keyFile = &Global::getCourseKeyFile($inputs{'course'}); 73 74 #verify session key 75 &verify_key($inputs{'user'}, $inputs{'key'}, $keyFile, $inputs{'course'}); 76 77 # verify permissions are correct 78 if ($permissions != $Global::instructor_permissions ) { 79 print "permissions = $permissions instructor_permissions = $Global::instructor_permissions\n"; 80 print &html_NO_PERMISSION; 81 exit(0); 82 } 83 # get the rest of the information from the submitted form 84 85 86 my $number = $inputs{'number'}; 87 my $page = $inputs{'page'}; 88 my @setNumbers =(); 89 @setNumbers = $cgi -> param('setNo' ); 90 91 my $setDefinitionFile; 92 my $setNumber; 93 my ($time1, $time2, $time3); 94 95 my @added_student_logins =(); 96 97 $number = min(100, int($number)); 98 $number = max(1, $number); 99 100 my $action = $inputs{Action}; 101 102 if ($action eq 'return') { 103 print_add_student_form(); 104 } 105 elsif ($action eq 'Add Students') { 106 $time1 = &unformatDateAndTime($inputs{'OpenDate'}); 107 $time2 = &unformatDateAndTime($inputs{'DueDate'}); 108 $time3 = &unformatDateAndTime($inputs{'AnswerDate'}); 109 110 test_inputs(); 111 my $msg1 = add_students(); 112 my $msg2 = build_sets(); 113 change_dates(); 114 #trim_msg(\$msg2); 115 print_html($msg1,$msg2); 116 } 117 118 119 # begin Timing code 120 if ($logTimingData == 1) { 121 my $endTime = new Benchmark; 122 &Global::logTimingInfo($beginTime,$endTime,"dataMunger.pl",$Course,$User); 123 } 124 # end Timing code 125 exit; 126 127 ## end of main script 128 129 sub print_add_student_form { 130 131 # print HTML text 132 print &htmlTOP("Add Student(s) Page"); 133 134 # print navigation buttons 135 print qq! 136 <A HREF="${cgiURL}profLogin.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}"> 137 <IMG SRC="${Global::upImgUrl}" align="right" BORDER=1 ALT="[Up]"></A><p> 138 !; 139 140 print <<EOF; 141 <HR><BR> 142 143 <h3 align="left">Add Student(s) to $Course</h3> 144 145 From this page you add from one to five students to $Course. 146 EOF 147 148 print qq! <FORM METHOD = "POST" ACTION= "${cgiURL}profAddStudent.pl"> \n!; 149 150 #start_form('POST', "${Global::cgiWebworkURL}profAddStudent.pl"), 151 print 152 'If you want to add more at one time, enter the total number ', 153 textfield('number',5,3), "\n", 154 'and hit '; 155 print <<EOF; 156 <INPUT TYPE=SUBMIT NAME='Action' VALUE='return'> 157 EOF 158 159 160 161 print <<EOF; 162 <p>Usually this page is used 163 to add students who have entered the course after it has started. This will add students 164 to the claslist database and initialize passwords for them. Also select the set(s) to build for 165 the student(s). All sets which have already been built for students in the course are listed. 166 Finally enter open, due, and answer dates (or use the defaults). 167 These dates will be used for all students (listed on this page) and all sets. 168 <p> 169 The Student ID is often a Social Security Number. Note that both the student ID and the Login Name 170 must be different than any other student's Id or Login Name. (WeBWorK will check for duplicates.) 171 <p> 172 EOF 173 174 175 176 177 178 179 #print qq! <FORM METHOD = "POST" ACTION= "${cgiURL}profAddStudent.pl"> \n!; 180 181 print qq! <TABLE BORDER="1" CELLPADDING="0" CELLSPACING="1" > !; 182 183 print "<TR>\n"; 184 print &formatHeaderCell("Last Name"); 185 print &formatHeaderCell("First Name"); 186 print &formatHeaderCell("Student ID" ); 187 print &formatHeaderCell("Login Name"); 188 print &formatHeaderCell("Section"); 189 print &formatHeaderCell("Recitation"); 190 print &formatHeaderCell("Email Address" ); 191 192 193 print "</TR>\r\n"; 194 my ($i,$sln,$sfn,$sid,$sli,$sec,$rec,$sea); 195 196 for ($i=1; $i <= $number; $i++) { 197 print "<TR>\r\n"; 198 $sln =''; 199 $sln = stripWhiteSpace($inputs{"StudentLastName$i"}) if defined $inputs{"StudentLastName$i"}; 200 print &formatDataCell("StudentLastName$i","$sln", '16'); 201 $sfn =''; 202 $sfn = stripWhiteSpace($inputs{"StudentFirstName$i"}) if defined $inputs{"StudentFirstName$i"}; 203 print &formatDataCell("StudentFirstName$i", "$sfn", '13'); 204 $sid =''; 205 $sid = stripWhiteSpace($inputs{"StudentID$i"}) if defined $inputs{"StudentID$i"}; 206 print &formatDataCell("StudentID$i", "$sid", '12'); 207 $sli =''; 208 $sli = stripWhiteSpace($inputs{"LoginName$i"}) if defined $inputs{"LoginName$i"}; 209 print &formatDataCell("LoginName$i","$sli", '10'); 210 $sec =''; 211 $sec = stripWhiteSpace($inputs{"Section$i"}) if defined $inputs{"Section$i"}; 212 print &formatDataCell("Section$i", "$sec", '10'); 213 $rec =''; 214 $rec = stripWhiteSpace($inputs{"Recitation$i"}) if defined $inputs{"Recitation$i"}; 215 print &formatDataCell("Recitation$i", "$rec", '10'); 216 $sea =''; 217 $sea = stripWhiteSpace($inputs{"EmailAddress$i"}) if defined $inputs{"EmailAddress$i"}; 218 print &formatDataCell("EmailAddress$i", "$sea", '24'); 219 220 print "</TR>\r\n"; 221 } 222 print qq! </TABLE >!; 223 224 print qq! <p>Select the set(s) and enter appropriate dates (or use the defaults) 225 if you want to build sets for the above student(s). You can submit this form multiple 226 times to build sets with different due dates. If you do not select any sets 227 (or select none) no sets will be built. If you want the new students to 228 have the same due dates other students have, do not build sets here but after 229 adding the students, go to the Build Problem Set page and build sets there.<p>!; 230 my %availableSets = &getAllProbSetNumbersHash; 231 my @sortedSetNames = &sortSetNamesByDueDate(\%availableSets); 232 my $ind; 233 234 # enter the available set numbers 235 236 237 238 ## enter open, due and answer dates 239 # format the dates properly 240 my $timeOpen = time; 241 $timeOpen = int($timeOpen/3600)*3600; ## previous hour 242 my $timeDue = $timeOpen + 14*24*3600 +3600; ## 14 days from next hour 243 my $timeAnswer = $timeOpen + 15*24*3600+ 3600; ## 15 days from next hour 244 245 my $OpenDate = &formatDateAndTime($timeOpen); 246 my $DueDate = &formatDateAndTime($timeDue); 247 my $AnswerDate = &formatDateAndTime($timeAnswer); 248 249 # print qq! <TABLE BORDER='1' CELLPADDING='0' CELLSPACING='1' > !; 250 print qq! <TABLE > !; 251 print "<TR>\n"; 252 print &formatHeaderCell('Sets'); 253 254 255 print &formatHeaderCell(' '); 256 print &formatHeaderCell('Open Date'); 257 print &formatDataCell("OpenDate",$OpenDate, '17'); 258 259 print &formatHeaderCell(' '); 260 print "<TD colspan = 2>\n"; 261 print 'The drop down lists below are for information only. Selecting items from them does nothing. Enter the section and 262 recitation data, if any, above.'; 263 264 print "<TR>\n"; 265 266 print "<TD rowspan = '3'>\n"; 267 print qq! <SELECT Name = 'setNo' Size =4 multiple>\n!; 268 print "<OPTION VALUE = none>none\n"; 269 for $ind (@sortedSetNames) { 270 print "<OPTION VALUE = \"$ind\">Set $ind\n"; 271 } 272 print qq!</SELECT>\n!; 273 print "</TD>\n"; 274 275 print &formatHeaderCell(' '); 276 print &formatHeaderCell('Due Date'); 277 print &formatDataCell("DueDate", $DueDate, '17'); 278 279 280 print &formatHeaderCell(' '); 281 print '<td>'; 282 # Current Sections list 283 print $cgi -> popup_menu( -name => 'currentSections', 284 -values => ['List of current sections', keys (%{getAllSections()})] 285 ); 286 287 print '<td>'; 288 # Current Recitations list 289 print $cgi -> popup_menu( -name => 'currentRecitations', 290 -values => ['List of current recitations', keys (%{getAllRecitations()})] 291 ); 292 293 294 print "<TR>\n"; 295 print &formatHeaderCell(' '); 296 print &formatHeaderCell('Answer Date' ); 297 print &formatDataCell("AnswerDate", $AnswerDate, '17'); 298 299 300 print qq! </TABLE >!; 301 302 303 print qq! <BR><INPUT TYPE=SUBMIT NAME='Action' VALUE='Add Students'>!; 304 305 ## resume printing the rest of the form 306 print <<EOF; 307 <INPUT TYPE='HIDDEN' NAME='page' VALUE='second'> 308 <INPUT TYPE='HIDDEN' NAME='user' VALUE="$inputs{'user'}"> 309 <INPUT TYPE='HIDDEN' NAME='key' VALUE="$inputs{'key'}"> 310 <INPUT TYPE='HIDDEN' NAME='course' VALUE="$inputs{'course'}"> 311 </FORM> 312 EOF 313 314 #print &sessionKeyInputs(\%inputs); # this duplicates the user, key and course hidden variables and kills some browsers. !!!! 1/21/01/ MEG 315 316 print &htmlBOTTOM("profAddStudent.pl", \%inputs); 317 } 318 319 320 321 322 sub formatDataCell { 323 my ($name,$value,$size) = @_; 324 # if the data hasn't been entered it appears as a blank: 325 $value = '' unless defined($value); 326 327 my $out = qq! 328 <TD ALIGN=CENTER VALIGN=MIDDLE > 329 <INPUT TYPE="TEXT" NAME="$name" VALUE="$value" SIZE="$size"> 330 </TD> 331 !; 332 $out; 333 } 334 335 sub formatHeaderCell { 336 my ($item,$options) = @_; 337 $options = "" unless defined($options); 338 my $out = qq! 339 <TH ALIGN=CENTER VALIGN=MIDDLE $options> 340 $item 341 </TH> 342 !; 343 $out; 344 } 345 346 347 sub add_students { 348 my ($i,$sln,$sfn,$sid,$sli,$sec,$rec,$sea); 349 my $msg = ''; 350 my $tmp1_msg = ''; 351 my $tmp2_msg = ''; 352 my $uniqueSection; 353 my $uniqueRecitation; 354 355 for ($i=1; $i <= $number; $i++) { 356 $sln =''; 357 $sln = stripWhiteSpace($inputs{"StudentLastName$i"}) if defined $inputs{"StudentLastName$i"}; 358 $sfn =''; 359 $sfn = stripWhiteSpace($inputs{"StudentFirstName$i"}) if defined $inputs{"StudentFirstName$i"}; 360 $sid =''; 361 $sid = stripWhiteSpace($inputs{"StudentID$i"}) if defined $inputs{"StudentID$i"}; 362 $sli =''; 363 $sli = stripWhiteSpace($inputs{"LoginName$i"}) if defined $inputs{"LoginName$i"}; 364 $sec =''; 365 $sec = stripWhiteSpace($inputs{"Section$i"}) if defined $inputs{"Section$i"}; 366 $rec =''; 367 $rec = stripWhiteSpace($inputs{"Recitation$i"}) if defined $inputs{"Recitation$i"}; 368 $sea =''; 369 $sea = stripWhiteSpace($inputs{"EmailAddress$i"}) if defined $inputs{"EmailAddress$i"}; 370 371 next unless ( $sln or $sfn or $sid or $sli or $sec or $rec or $sea); 372 373 $tmp1_msg = testNewStudentLogin($sli,$sid); 374 $tmp2_msg = testNewStudentID($sid,$sli); 375 unless (($tmp1_msg eq 'OK') and ($tmp2_msg eq 'OK')) { 376 $msg .= "\n Skipping the entry: $sln, $sfn, $sid, $sli, $sec, $rec, $sea\n"; 377 $msg .= $tmp1_msg unless $tmp1_msg eq 'OK'; 378 $msg .= $tmp2_msg unless $tmp2_msg eq 'OK'; 379 next; 380 } 381 # add to classlist database 382 383 &CL_putStudentID ($sid, $sli); 384 &CL_putStudentLastName ($sln, $sli); 385 &CL_putStudentFirstName ($sfn, $sli); 386 &CL_putStudentStatus ('C', $sli); 387 &CL_putComment ('', $sli); 388 &CL_putClassSection ($sec,$sli); 389 &CL_putClassRecitation ($rec,$sli); 390 &CL_putStudentEmailAddress ($sea, $sli); 391 # now we can save the classlist record 392 &saveCLRecord($sli); 393 394 # these will be set to 1 if the new section or recitation is unique 395 $uniqueSection = getAllSections()->{$sec}; 396 $uniqueRecitation = getAllRecitations()->{$rec}; 397 398 399 $msg .= "\n At this point,<FONT COLOR='#ff00aa'><B> $sfn $sln is the only person in the section $sec</B></font>" unless $uniqueSection > 1; 400 401 $msg .= "\n At this point,<FONT COLOR='#ff00aa'><B> $sfn $sln is the only person in the recitation $rec</B></font>" unless $uniqueRecitation >1; 402 403 ## add to password and permissions databases 404 &new_password($sli, $sid, $passwordFile); 405 &put_permissions(0,$sli,$permissionsFile); 406 407 push (@added_student_logins, $sli); 408 409 $msg .= "\nadded $sfn $sln ($sli, $sid) to password database"; 410 411 } 412 $msg; 413 } 414 415 416 sub build_sets { 417 418 my $msg = ''; 419 my $method ='createNewPSVNs'; 420 my $setDefinitionFile; 421 my $outputFormat = 'new_students'; 422 423 foreach $setNumber (@setNumbers) { 424 next if $setNumber eq 'none'; 425 $setDefinitionFile = "set${setNumber}.def"; 426 my $message = &buildProbSetDB($Course,$setDefinitionFile,$method,'',$outputFormat); 427 $msg .= "<pre> $message </pre><HR>"; 428 $outputFormat = 'no_students'; ## if format is all_students, only list them the first time. 429 } 430 ## clean up message --- remove dates which 431 $msg =~ s/openDate.*?Loading/Loading/gs; 432 $msg; 433 } 434 435 sub change_dates { 436 my $sli; 437 ## return unless we have built some sets 438 my $num_of_sets = @setNumbers; 439 440 return unless (($num_of_sets > 1) or (($num_of_sets == 1) and ($setNumbers[0] ne 'none'))); 441 foreach $sli (@added_student_logins){ 442 my %setNumberHash=&getAllSetNumbersForStudentLoginHash($sli); 443 foreach $setNumber (@setNumbers) { 444 next if $setNumber eq 'none'; 445 next unless defined $setNumberHash{$setNumber}; 446 my $psvn = $setNumberHash{$setNumber}; 447 attachProbSetRecord($psvn); 448 putOpenDate ($time1, $psvn); 449 putDueDate ($time2, $psvn); 450 putAnswerDate ($time3, $psvn); 451 detachProbSetRecord($psvn); 452 } 453 } 454 } 455 sub test_inputs { 456 ## verify dates are OK 457 458 if ($time2 < $time1 or $time3 < $time2) { 459 &wwerror("ERROR IN DATES. NO STUDENTS HAVE BEEN ADDED TO $Course and no sets have been built.<P>", "Dates are not in chronological order. The open date: $inputs{'OpenDate'}, 460 due date: $inputs{'DueDate'}, and answer date: $inputs{'AnswerDate'} must be in chronological order. <P> Use the back button to go back and fix the problem."); 461 } 462 463 ## verify set definition files are OK 464 465 foreach $setNumber (@setNumbers) { 466 next if $setNumber eq 'none'; 467 $setDefinitionFile = "set${setNumber}.def"; 468 wwerror ("ERROR IN READING SET DEFINITION FILES. NO STUDENTS HAVE BEEN ADDED TO $Course and no sets have been built.<P>", 469 "Can not read set definition file ${templateDirectory}$setDefinitionFile. 470 <P> Fix the problem and then go back and rerun this job.") 471 unless -R "${templateDirectory}$setDefinitionFile"; 472 } 473 } 474 475 sub print_html { 476 my ($msg1,$msg2) = @_; 477 478 # print HTML text 479 print &htmlTOP("Add Students and Build Problem Sets"); 480 481 # print navigation buttons 482 print qq! 483 <A HREF="${cgiURL}profAddStudent.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}&number=$inputs{'number'}&Action=return"> 484 <IMG SRC="${Global::upImgUrl}" align="right" BORDER=1 ALT="[Up]"></A><p> 485 !; 486 print "<H2><B>INFORMATION ON ADDING STUDENTS TO $Course</B></H2>"; 487 print "<pre>$msg1</pre>"; 488 print "<H2><B>INFORMATION ON BUILDING PROBLEM SETS FOR $Course</B></H2>"; 489 print "<pre>$msg2</pre>"; 490 print "<H2><B>DONE ADDING STUDENTS AND BUILDING SETS</B></H2>"; 491 print &htmlBOTTOM("profAddStudent.pl", \%inputs); 492 }
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |