|
Home About
FAQs
General Admin Assist Student
Docs
Admin Assistant
CGI
Admin Assistant Download Form Student
Packages
AdminInterface Assignments AssistantInterface Form Interface Record Roster StudentInterface SystemVariables Teams VincentFile VincentLog |
|
0 #Student Record Manipulation Package 1 #Copyright 2000 Matt Jadud 2 #This program is free software; you can redistribute it and/or 3 #modify it under the terms of the GNU General Public License 4 #as published by the Free Software Foundation; either version 2 5 #of the License, or (at your option) any later version. 6 # 7 #This program is distributed in the hope that it will be useful, 8 #but WITHOUT ANY WARRANTY; without even the implied warranty of 9 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 #GNU General Public License for more details. 11 # 12 #You should have received a copy of the GNU General Public License 13 #along with this program; if not, write to the Free Software 14 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 150 1 use SystemVariables; 2 3 package Record; 4 5 my($DEBUG); 6 $DEBUG = 0; 7 $| = 1; 8 9 #Last executing statement 10 # in a package must be a return. 11 return 1; 12 13 sub getDebugLevel { 14 15 my($username, 16 $data); 17 18 $username = $_[0]; 19 20 $recordpath = SystemVariables::getRecordPath(); 21 if(-e $recordpath . "$username") { 22 $data = getStudentRecord($username); 23 24 if($$data{"_DEBUGLEVEL"}) { 25 return $$data{"_DEBUGLEVEL"}; 26 } 27 } 28 29 return 0; 30 } 31 32 33 ##CONTRACT 34 # getDownloadPermissionFile : String -> String 35 ##PURPOSE 36 # Takes a username, and returns the path to that 37 # user's download permissions file. 38 ##DEPENDANCIES 39 # SystemVariables::getRecordPath() 40 sub getDownloadPermissionsFile { 41 42 my($user, $path); 43 44 $user = $_[0]; 45 $path = SystemVariables::getRecordPath(); 46 $path .= "$user/downloadPermissions"; 47 48 } 49 50 sub getStudentBySSN { 51 52 my($sid, 53 $path, 54 $match, 55 $student, 56 $thisSSN, 57 $stu 58 ); 59 60 $sid = $_[0]; 61 @allStudents = getAllStudentUsernames(); 62 63 if($sid) { 64 65 foreach $stu (@allStudents) { 66 $data = getStudentRecord($stu); 67 if($$data{"_SID"} =~ /$sid/) { 68 return $$data{"_USERNAME"}; 69 } 70 } 71 } 72 73 return "NOTASTUDENT"; 74 75 } 76 77 sub expireStudent { 78 79 my ($sid, 80 $data 81 ); 82 83 $sid = $_[0]; 84 85 SystemVariables::DEBUG("Record:","Looking for student with $sid as a Student ID"); 86 87 #If they are a student, set their expiration to 88 # NOW. If they aren't, don't worry. 89 $username = getStudentBySSN($sid); 90 91 SystemVariables::DEBUG("Record:","Found $username with $sid."); 92 93 if(isStudent($username)) { 94 $data = getStudentRecord($username); 95 SystemVariables::DEBUG("Record:","<FONT COLOR='RED'>Expiring $username.</FONT>"); 96 $$data{"_EXPIRATION"} = SystemVariables::getCurrentTime(); 97 updateStudentRecord($username, $data); 98 } 99 } 100 101 ##CONTRACT 102 # isStudent : String -> Boolean 103 ##PURPOSE 104 # Takes a username, and checks whether the 105 # user is in the system (either through the 106 # roster, or as an addition by the admin). 107 ##DEPENDANCIES 108 sub isStudent { 109 110 my ($username, 111 @allstudents 112 ); 113 114 #Anything in this tree will cause deep recursion, as 115 # SystemVariables::DEBUG calls this routine. 116 $username = $_[0]; 117 @allstudents = getAllStudentUsernames(); 118 119 120 #SystemVariables::DEBUG("Record:","In isStudent checking $username"); 121 122 #If they are in the list of all students, then 123 # they are a student. 124 if(SystemVariables::existInList($username, @allstudents)) { 125 #SystemVariables::DEBUG("Record:","$username IS A STUDENT!"); 126 return 1; 127 } 128 129 return 0; 130 } 131 132 ##CONTRACT 133 # isGod : String -> Boolean 134 # takes a username, and checks to see if the 135 # user is in the "god" list. 136 ##DEPENDANCIES 137 # SystemVariables::getGodString() 138 sub isGod { 139 140 my($username); 141 142 $username = $_[0]; 143 144 if (SystemVariables::getGodString() =~ /$username/) { 145 SystemVariables::DEBUG("Record:","Found $username in godstring"); 146 return 1; 147 } 148 149 return 0; 150 151 } 152 ##CONTRACT 153 # isAdministrator : String -> Boolean 154 ##PURPOSE 155 # Takes a username, and checks to see if the 156 # the user is in the admin list. 157 ##DEPENDANCIES 158 # SystemVariables::getAdminString() 159 sub isAdministrator { 160 161 my($username); 162 163 $username = $_[0]; 164 165 if (SystemVariables::getAdminString() =~ /$username/) { 166 return 1; 167 } 168 169 return 0; 170 171 } 172 173 ##CONTRACT 174 # isAssistant : String -> Boolean 175 ##PURPOSE 176 # Takes a username, and checks to see if it 177 # is in the assistant list. 178 ##DEPENDANCIES 179 # SystemVariables::getAssistString() 180 sub isAssistant { 181 182 my($username); 183 184 $username = $_[0]; 185 186 if (SystemVariables::getAssistString() =~ /$username/) { 187 return 1; 188 } 189 190 return 0; 191 192 } 193 194 ##CONTRACT 195 # getAllSectionNumbers : Void -> Array 196 ##PURPOSE 197 # Returns a list of all section numbers in the class 198 ##DEPENDANCIES 199 # SystemVariables::getCourseConfigPath(); 200 sub getAllSectionNumbers { 201 202 my($configpath, 203 @allNumbers, 204 $username); 205 206 $configpath = SystemVariables::getCourseConfigPath(); 207 208 209 open(LIST, $configpath . "sectionnumberlist") || return "NO SECTIONS."; 210 211 while(<LIST>) { 212 push(@allNumbers, $_); 213 } 214 215 close(LIST); 216 217 return @allNumbers; 218 } 219 220 ##CONTRACT 221 # getAllSectionNumbersFromDB : Void -> Array 222 ##PURPOSE 223 # Returns a list of all section numbers in the class 224 # by searching each student record, and creating 225 # a unique list of section numbers based on this 226 # search. 227 ##DEPENDANCIES 228 # SystemVariables::getCourseCorrellationFile() 229 sub getAllSectionNumbersFromDB { 230 231 my ($sectionnumber, 232 @sections, 233 @newlist, 234 $next, 235 $i, 236 @allstudents, 237 $student, 238 $data 239 ); 240 241 @allstudents = getAllStudentUsernames(); 242 243 foreach $student (@allstudents) { 244 $data = getStudentRecord($student); 245 push(@sections, $$data{"_SECTIONNUMBER"}); 246 } 247 248 if(@sections) { 249 chomp @sections; 250 $index = 0; 251 $length = $#sections; 252 @newlist = (); 253 254 #print @sections, "<P>"; 255 #Work on the assumption that the first is unique; 256 # This won't get revisited. 257 push(@newlist, $sections[0]); 258 259 #THIS IS AWFUL! Perl wraps -1 to the end of 260 # the list; so, going from -1 to $length gets 261 # us a comparison of everything in the list in 262 # a for loop.... ugly, ugly language. 263 for($i=0;$i<$length;$i++) { 264 $next = $i+1; 265 266 if($sections[$i] != $sections[$next]) { 267 #print $sections[$i], ",", $sections[$next], "<P>"; 268 @newlist = (@newlist, $sections[$next]); 269 } 270 } 271 272 undef %saw; 273 @newlist = grep(!$saw{$_}++, @newlist); 274 275 if(@newlist) { 276 return sort(@newlist); 277 } 278 } 279 280 #Default behavior 281 return "NO SECTIONS"; 282 } 283 284 285 ##CONTRACT 286 # getNextFilename : String -> String 287 ##PURPOSE 288 # Takes a username, and finds what the next indexed 289 # username.### file is in their directory. 290 # Returns the new filename. 291 ##DEPENDANCIES 292 # SystemVariables::getRecordPath() 293 # Record::getNextIndex() 294 sub getNextFilename { 295 296 my ($username, 297 @files, 298 $path, 299 $index 300 ); 301 302 $username = $_[0]; 303 $path = SystemVariables::getRecordPath() . "$username/"; 304 305 @files = glob("$path" . "$username.*"); 306 307 @files = sort { yankIndex($a) <=> yankIndex($b) } @files; 308 309 $index = getNextIndex($username, pop(@files)); 310 311 return $username . "." . $index; 312 313 } 314 315 sub yankIndex { 316 317 my ($f1, $num); 318 319 $f1 = $_[0]; 320 321 $f1 =~ /.*/.*.(d+)$/; 322 323 return $1; 324 325 } 326 327 ##CONTRACT 328 # getNextIndex : String String -> Number 329 ##PURPOSE 330 # Takes a username and a filename, and returns 331 # the next index based on that filename. So, 332 # given "mjadud" and "mjadud.1", it would 333 # return "mjadud.2" 334 ##DEPENDANCIES 335 # None. 336 sub getNextIndex { 337 338 my ($filename, 339 $index, 340 $username 341 ); 342 343 $username = $_[0]; 344 $filename = $_[1]; 345 346 if($filename) { 347 SystemVariables::DEBUG("Record:","Next index from: $filename<P>"); 348 349 $filename =~ /.*/$username.(d+)$/; 350 $index = $1; 351 352 SystemVariables::DEBUG("Record:","Current Index: $index"); 353 354 chomp $index; 355 $index = $index + 1; 356 } else { 357 $index = 1; 358 } 359 360 return $index; 361 } 362 363 #Use of uninitialized value in concatenation (.) at /l/cgi/mjadud/.vincent3/modules//Record.pm line 297. 364 #Use of uninitialized value in pattern match (m//) at /l/cgi/mjadud/.vincent3/modules//Record.pm line 299. 365 #Use of uninitialized value in concatenation (.) at /l/cgi/mjadud/.vincent3/modules//Record.pm line 302. 366 #Use of uninitialized value in scalar chomp at /l/cgi/mjadud/.vincent3/modules//Record.pm line 304. 367 #Use of uninitialized value in addition (+) at /l/cgi/mjadud/.vincent3/modules//Record.pm line 305. 368 369 ##CONTRACT 370 # getParamFilePath : String -> String 371 ##PURPOSE 372 # Returns a path to the .username.param file in 373 # each student's record space. This file 374 # contains all the data regarding that student's 375 # file uploads, permissions, grades, etc... 376 ##DEPENDANCIES 377 # SystemVariables::getRecordPath() 378 sub getParamFilePath { 379 380 my ($username, 381 $parampath 382 ); 383 $username = $_[0]; 384 $parampath = SystemVariables::getRecordPath(); 385 $parampath .= $username; 386 $parampath .= "/.$username"; 387 $parampath .= ".param"; 388 389 return $parampath; 390 } 391 392 ##CONTRACT 393 # getStudentFilelog : String -> String 394 ##PURPOSE 395 # Takes a username, and returns the path to the 396 # file log for that particular student. 397 ##DEPENDANCIES 398 # SystemVariables::getRecordPath() 399 sub getStudentFilelog { 400 401 my($username, 402 $path); 403 404 $username = $_[0]; 405 $path = SystemVariables::getRecordPath(); 406 $path .= $username; 407 $path .= "/filelog"; 408 return $path; 409 } 410 411 ##CONTRACT 412 # getFirstName : String -> String 413 ##PURPOSE 414 # Takes a username, and returns that user's first name. 415 ##DEPENDANCIES 416 # Record::getRecord() 417 sub getFirstName { 418 return getRecord($_[0], "_FIRSTNAME"); 419 } 420 421 ##CONTRACT 422 # getLastName : String -> String 423 ##PURPOSE 424 # Takes a username, and returns that user's last name. 425 ##DEPENDANCIES 426 # Record::getRecord() 427 sub getLastName { 428 return getRecord($_[0], "_LASTNAME"); 429 } 430 431 ##CONTRACT 432 # getSID : String -> String 433 ##PURPOSE 434 # Takes a username, and returns that user's student ID #. 435 ##DEPENDANCIES 436 # Record::getRecord() 437 sub getSID { 438 return getRecord($_[0], "_SID"); 439 } 440 441 ##CONTRACT 442 # getSectionNumber : String -> String 443 ##PURPOSE 444 # Takes a username, and returns that student's section number. 445 ##DEPENDANCIES 446 # Record::getRecord() 447 sub getSectionNumber { 448 return getRecord($_[0], "_SECTIONNUMBER"); 449 } 450 451 ##CONTRACT 452 # getSlipTime : String -> String 453 ##PURPOSE 454 # Takes a username, and returns that student's remaining 455 # slip time. 456 ##DEPENDANCIES 457 # Record::getRecord() 458 sub getSlipTime { 459 return getRecord($_[0], "_SLIPTIME"); 460 } 461 462 ##CONTRACT 463 # getExpirationDate : String -> String 464 ##PURPOSE 465 # Takes a username, and returns that students 466 # expiration date. 467 ##DEPENDANCIES 468 # Record::getRecord() 469 sub getExpirationDate { 470 return getRecord($_[0], "_EXPIRATION"); 471 } 472 473 ##CONTRACT 474 # isStudentExpired : String -> Boolean 475 ##PURPOSE 476 # Takes a username, and returns true 477 # if the student has expired. 478 ##DEPENDANCIES 479 # Record::getExpirationDate() 480 # SystemVariables::currentTime() 481 # SystemVariables::getEarlierDate() 482 sub isStudentExpired { 483 484 my ($studentUsername, 485 $date, 486 $expiration); 487 488 $studentUsername = $_[0]; 489 490 $expiration = getExpirationDate($studentUsername); 491 $date = SystemVariables::currentTime(); 492 493 if($date eq SystemVariables::getEarlierDate($date, $expiration)) { 494 return 0; 495 } else { 496 return 1; 497 } 498 499 } 500 501 ##CONTRACT 502 # updateAllStudentRecords : HashRef -> Void 503 ##PURPOSE 504 # Takes a hash ref of data, and updates every 505 # student's record with that data. 506 ##DEPENDANCIES 507 # Record::getAllStudentUsernames() 508 # Record::updateStudentRecord() 509 sub updateAllStudentRecords { 510 511 my ($student, 512 $students, 513 $data, 514 $path, 515 $key 516 ); 517 518 $data = $_[0]; 519 520 foreach $student (getAllStudentUsernames()) { 521 SystemVariables::DEBUG("Record:","Updating $student"); 522 updateStudentRecord($student, $data); 523 } 524 525 } 526 527 ##CONTRACT 528 # getAllUsernamesInSection : Number -> ArrayRef 529 ##PURPOSE 530 # Takes a section number, and returns a reference 531 # to an array containing all the usernames in that section. 532 ##DEPENDANCIES 533 # SystemVariables::getCourseCorrellationFile() 534 sub getAllUsernamesInSection { 535 536 my( $correllation_file, 537 $student, 538 @students, 539 $section, 540 $data, 541 @allstudents 542 ); 543 544 $section = $_[0]; 545 546 @allstudents = getAllStudentUsernames(); 547 548 if($section) { 549 chomp $section; 550 foreach $student (@allstudents) { 551 #SystemVariables::DEBUG("Record:","Found $student"); 552 $data = getStudentRecord($student); 553 554 if($section eq $$data{"_SECTIONNUMBER"}) { 555 push(@students, $student); 556 } 557 } 558 } else { 559 @students = @allstudents; 560 } 561 562 chomp @students; 563 564 return @students; 565 566 } 567 568 ##CONTRACT 569 # getAllStudentUsernames : Void -> Array 570 ##PURPOSE 571 # Returns a list of all usernames in the course. 572 # This should be fixed to return an array ref. 573 ##DEPENDANCIES 574 # SystemVariables::getCourseCorrellationFile() 575 sub getAllStudentUsernames { 576 577 getAllUsernamesFromFilesystem(); 578 } 579 580 #This is only used when rebuilding the correllation 581 # file from scratch; it actually reads the directories 582 # in the config directory, and uses those usernames to 583 # build a list of students in the system. 584 585 ##CONTRACT 586 # getAllUsernamesFromFilesystem : Void -> Array 587 ##PURPOSE 588 # Returns a list of all usernames from the filesystem, 589 # not the correllation file. After loading a new roster, 590 # there are hanger-oners who may have dropped, been 591 # added, etc. Those usernames are needed to rebuild/refresh 592 # the correllation file. Hence, we use this function. 593 ##DEPENDANCIES 594 # SystemVariables::getRecordPath() 595 sub getAllUsernamesFromFilesystem { 596 597 my ($student, 598 @students, 599 @filtered, 600 $record_path 601 ); 602 603 $record_path = SystemVariables::getRecordPath(); 604 605 opendir(RECORDS, $record_path) || die("Bad path to records. $record_path"); 606 @students = readdir(RECORDS); 607 closedir(RECORDS); 608 609 #Filter the directory of all . files 610 foreach (@students) { 611 if($_ !~ /^./) { 612 push(@filtered, $_); 613 } 614 } 615 616 chomp @filtered; 617 return @filtered; 618 } 619 620 ##CONTRACT 621 # updateStudentRecord : string REF(hash) -> void 622 ##PURPOSE 623 # Takes a student's username and a hash reference containing data 624 # to be added to their record, and updates their individual record 625 # with that data. 626 ##DEPENDANCIES 627 # Record::getStudentRecord() 628 # Record::writeStudentRecord() 629 sub updateStudentRecord { 630 631 my ($student, 632 $newdata, 633 $olddata, 634 $path, 635 $newkey, 636 $oldkey, 637 $oldusername, 638 $newusername 639 ); 640 641 $student = $_[0]; 642 $newdata = $_[1]; 643 644 #print STDERR "Getting old data for $student.\n"; 645 646 $olddata = getStudentRecord($student); 647 648 #Copy the new data into the olddata hash. 649 # This will overwrite any keys that were identical, 650 # which is file. 651 foreach $newkey (keys %{$newdata}) { 652 #print STDERR "Updating $newkey in olddata ", $$newdata{$newkey}, "\n"; 653 654 if(defined($$newdata{$newkey})) { 655 $$olddata{$newkey} = $$newdata{$newkey}; 656 SystemVariables::DEBUG("Record:","Updating $newkey to ", $$newdata{$newkey}); 657 } 658 } 659 660 #sleep 5; 661 #Write the record back to disk. 662 writeStudentRecord($student, $olddata); 663 664 665 } 666 667 ##CONTRACT 668 # writeStudentRecord : String HashRef -> Void 669 ##PURPOSE 670 # Writes a student's data to a file. Takes 671 # a username and the data to be added. Should 672 # never be called directly - always use updateStudent 673 # record, as that preloads the existing data, 674 # and the overwrites only the select bits being 675 # updated. This function is only an overwrite. 676 ##DEPENDANCIES 677 # Record::getParamFilePath() 678 sub writeStudentRecord { 679 680 my ($student, 681 $data, 682 $path, 683 $key 684 ); 685 686 $student = $_[0]; 687 $data = $_[1]; 688 $path = getParamFilePath($student); 689 690 open(PARAMS, ">$path"); 691 foreach $key (keys %{$data}) { 692 chomp $$data{$key}; 693 print PARAMS $key, "|", $$data{$key}, "n"; 694 } 695 close(PARAMS); 696 } 697 698 ##CONTRACT 699 # getStudentRecord : String -> HashRef 700 ##PURPOSE 701 # Takes a username, and returns all the 702 # data on that student as a hash reference. 703 ##DEPENDANCIES 704 # Record::getParamFilePath() 705 sub getStudentRecord { 706 707 my ($student, 708 %data, 709 $path, 710 $key, 711 $val 712 ); 713 714 $student = $_[0]; 715 $path = getParamFilePath($student); 716 717 open(PARAMS, $path) || die "Unable to open param file $path for $student"; 718 while(<PARAMS>) { 719 ($key, $val) = (split(/|/))[0,1]; 720 if($val) { 721 chomp $val; 722 } 723 724 $data{$key} = $val; 725 } 726 727 close(PARAMS); 728 729 return %data; 730 731 } 732 733 #Function: getRecord 734 #Input: Array (username, key) 735 #Return: Value 736 # Returns the value of an arbitrary key in the 737 # student record 738 739 ##CONTRACT 740 # getRecord : Array(String, String) -> String 741 ##PURPOSE 742 # Takes an array of a username and a hash key, and 743 # returns the value of that hash item in the student's 744 # record. 745 ##DEPENDANCIES 746 # SystemVariables::getRecordPath() 747 # Record::getParamFilePath() 748 sub getRecord { 749 750 my ( @INPUTARRAY, 751 $StudentUsername, 752 $RecordPath, 753 %StudentRecord, 754 $RequestedKey, 755 $path, 756 $key, 757 $value 758 ); 759 760 #@_ is not modifiable; hence the copy 761 # to another array before processing. 762 @INPUTARRAY = @_; 763 chomp @INPUTARRAY; 764 765 #Read in the username and requested record 766 $StudentUsername = $INPUTARRAY[0]; 767 $RequestedKey = $INPUTARRAY[1]; 768 769 #Get the path to the record built 770 $RecordPath = SystemVariables::getRecordPath(); 771 #$path = "$RecordPath" . "$StudentUsername" . "/$StudentUsername.param"; 772 $path = getParamFilePath($StudentUsername); 773 774 #Open the record 775 if(open(RECORD, $path)) { 776 777 #The records in this system are simply space delimited, 778 # and should be key/value pairs. 779 780 #If a match is found, return that value immediately 781 while(<RECORD>) { 782 chomp; 783 ($key, $value) = (split(/|/)); 784 785 if($key eq $RequestedKey) { 786 close(RECORD); 787 return $value; 788 } 789 } 790 791 close(RECORD); 792 } 793 794 #If no match was found, close the record, and return 795 # "NULL" 796 797 return ("NULL"); 798 799 } 800 801 ##CONTRACT 802 # DEBUG 803 ##PURPOSE 804 # Debugging. 805 ##DEPENDANCIES 806 # None. 807 sub useDebugging())'>DEBUG { if(SystemVariables::useDebugging()) { print "Record: ", @_, "n<P>"; } } 808 |
|
Last update: 1/6/01; 9:32:36 AM |