Roster
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 #Vincent's Roster Management System
  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.
 15 
 
  0 $| = 1;
  1 
  2 use SystemVariables;
  3 use VincentFile;
  4 
  5 package Roster;
  6 use Fcntl qw(:flock);  # imports LOCK_EX, LOCK_SH, LOCK_NB
  7 
  8 #Turn debugging on or off;
  9 $DEBUG = 1;
 10 
 11 ##CONTRACT
 12 # newRoster : String -> Void
 13 ##PURPOSE
 14 # Takes a roster (from a FILE input dialog), 
 15 # and loads it into the system.
 16 ##DEPENDANCIES
 17 # SystemVariables::getCourseConfigPath()
 18 # VincentFile::uploadBinaryFile()
 19 # Roster::createStudents()
 20 sub newRoster  {
 21     
 22     my ($roster,
 23 	$configpath
 24 	);
 25     
 26     $roster = $_[0];
 27      
 28      $configpath = SystemVariables::getCourseConfigPath();
 29 
 30   VincentFile::uploadBinaryFile( $roster,
 31 				 $configpath . ".roster");
 32 
 33     #With the student-centered record-based approach,
 34     # the correllation file might be old news... instead,
 35     # I just need to load the data into the student record...
 36     # I'll use the correllation file here only for storage of 
 37     # the data and building the student record.
 38 
 39     
 40     createStudentsTwo();
 41     
 42     updateSectionNumbers();
 43 
 44     createSectionNumberList();
 45 
 46     expireWithdrawnStudents();
 47     
 48 }
 49 
 50 sub createSectionNumberList  {
 51 
 52     my($configpath,
 53        @allNumbers,
 54        $username);
 55     
 56     $configpath = SystemVariables::getCourseConfigPath();
 57     @allNumbers = Record::getAllSectionNumbersFromDB();
 58     
 59     open(LIST, ">" . $configpath . "sectionnumberlist");
 60     
 61     foreach (@allNumbers) {
 62 	chomp;
 63 	print LIST $_, "n";
 64     }
 65 
 66     close(LIST);
 67     
 68 }
 69 
 70 sub updateSectionNumbers  {
 71 
 72     my($configpath,
 73        $roster,
 74        $sectionnumber,
 75        $username);
 76     
 77     $configpath = SystemVariables::getCourseConfigPath();
 78     $roster = $configpath . ".roster";
 79  
 80     open(ROSTER, $roster) || die ("Can't update sectionnumbers from $roster");
 81 
 82     while(<ROSTER>) {
 83 	if(/,INDIANA.EDU(r)*$/) {
 84 	    ($username, $sectionnumber) = (split(/,/))[6,2];
 85 	    updateSectionNumber($username, $sectionnumber);
 86 	}
 87     }
 88     close(ROSTER);
 89 
 90 }
 91 
 92 sub updateSectionNumber  {
 93 
 94     my($user, $section, $data);
 95     
 96     $user = $_[0];
 97     $section = $_[1];
 98 
 99     $user = lc($user);
 100     chomp $user;
 101     $user =~ s/s*//g;
 102 
 103     if(length($user) >= 2) {
 104 	
 105 	#SystemVariables::DEBUG(Roster, "Trying to update $user in section $section");
 106 	
 107 	if($user !~ /*/) {
 108 	    if(Record::isStudent($user)) {
 109 		$data = Record::getStudentRecord($user);
 110 		SystemVariables::DEBUG("Roster", "Updating ", $$data{"_SECTIONNUMBER"}, " to ", $section, " for $user.");
 111 		
 112 		#print STDERR "Updating $user to $section\n";
 113 
 114 		$$data{"_SECTIONNUMBER"} = $section;
 115 		
 116 
 117 	      Record::updateStudentRecord($user, $data);
 118 	    }
 119 	}
 120     }
 121 }
 122 
 123 sub expireWithdrawnStudents  {
 124 
 125     my($configpath,
 126        $roster,
 127        $ssn,
 128        $user, $sectionnumber,
 129        $line);
 130     
 131     $configpath = SystemVariables::getCourseConfigPath();
 132     $roster = $configpath . ".roster";
 133  
 134     open(ROSTER, $roster) || die ("Can't expire from $roster");
 135     
 136     while(<ROSTER>) {
 137 	$line = $_;
 138 
 139 	if($line =~ /WITHDRAWN.*INDIANA.EDU(r)*$/) {
 140 	    ($ssn) = (split(/,/))[3];
 141 	  Record::expireStudent($ssn);
 142 	} 
 143     }
 144     close(ROSTER);
 145 
 146 }
 147 
 148 
 149 ##CONTRACT
 150 # createStudent : String HashRef -> void
 151 ##PURPOSE
 152 # No purpose yet...
 153 ##DEPENDANCIES
 154 # SystemVariables::getRecordPath()
 155 # SystemVariables::getCourseConfigPath()
 156 # Record::getParamFilePath()
 157 # SystemVariables::getStudentDefaults()
 158 sub createStudent  {
 159     
 160     my ( $recordpath,
 161 	 $configpath,
 162 	 $username,
 163 	 $sysdefaults,
 164 	 $param,
 165 	 $assign,
 166 	 @assignments,
 167 	 @filename,
 168 	 $studentdata,
 169 	 $currdefaults
 170 	 );
 171     
 172     $recordpath = SystemVariables::getRecordPath();
 173     $configpath = SystemVariables::getCourseConfigPath();
 174 
 175     $username    = $_[0];
 176     $studentdata = $_[1];
 177     
 178     chomp $username;
 179     chomp $recordpath;
 180 
 181     #If a directory does not exist for the student,
 182     # create it.
 183     if(! Record::isStudent($username)) {
 184 	SystemVariables::DEBUG("Roster", "<STRONG>CREATING $username</STRONG>");
 185 
 186 	mkdir($recordpath . $username);
 187         
 188 	#Now, each student needs to inherit all of the default
 189 	# info that a student record needs to exist... what is that?
 190 	# and where to put it...
 191 
 192 	open(STUDENT, ">" . Record::getParamFilePath($username));
 193 
 194 	#getStudentDefaults returns a hash reference
 195 	# write out all the student defaults to the student's
 196 	# param file
 197 	$sysdefaults = SystemVariables::getStudentDefaults();
 198 	foreach $param (keys %{$sysdefaults}) {
 199 	    print STUDENT $param, "|", $$sysdefaults{$param}, "n";
 200 	}
 201 
 202 	#Add the student's personal data to the file.
 203 	foreach $param(keys %{$studentdata}) {
 204 	    print STUDENT $param, "|", $$studentdata{$param}, "n";
 205 	}
 206 	
 207 	#######################
 208 	# WARNING! WARNING!
 209 	#######################
 210 	# All of this assignment stuff really should be
 211 	# in the Assignment.pm module. Make a point
 212 	# to put it therre sometime soon!
 213 	####################################################
 214 
 215 	#Now, copy the contents of all assignments currently in
 216 	# the system to the student record.
 217 	@assignments = glob("$configpath" . "ASSIGN*");
 218 
 219 	foreach $assign (@assignments) {
 220 	    open(ASSIGN, $assign);
 221 
 222 	    #Only write out the data that beings with an underscore;
 223 	    # some other garbage makes it into the ASSIGN files,
 224 	    # and we don't want that here...
 225 	    while(<ASSIGN>) {
 226 		if(/^_/){
 227 		    @filename = (split(///, $assign));
 228 		    print STUDENT $filename[$#filename] . $_;
 229 		}
 230 	    }
 231 	    close(ASSIGN);
 232 	}
 233 	
 234 	#ADD In the forms.
 235 	@forms = glob($configpath . "FORM*");
 236 	
 237 	foreach $assign (@forms) {
 238 	    open(ASSIGN, $assign);
 239 	    
 240 	    while(<ASSIGN>) {
 241 		@filename = (split(///, $assign));
 242 		print STUDENT $filename[$#filename] . $_;
 243 	    }
 244 	    close(ASSIGN);
 245 	}
 246 	#Close the student so as to be able to grab data
 247 	# from their record quickly.
 248 	close(STUDENT);
 249 
 250     } else {
 251 	
 252 	#Update the student's record.
 253 	  Record::updateStudentRecord($username, $studentdata);
 254 	
 255     }
 256 
 257     #In the event that this student is in a new 
 258     # section, call the updater for the 
 259     # section number list.
 260 
 261     createSectionNumberList();
 262 }
 263 
 264 
 265 ##CONTRACT
 266 # createStudentsTwo : used to be createCorrellationFile
 267 ##PURPOSE
 268 # This actually cleans up the roster and
 269 # creates a usable file for generating
 270 # all student data from.
 271 ##DEPENDANCIES
 272 # SystemVariables::getCourseConfigPath()
 273 # Roster::parseRosterLine()
 274 #sub makeCorrellationFile {
 275 sub createStudentsTwo  {
 276 
 277     my($username,
 278        $sectionnumber,
 279        $firstname,
 280        $lastname,
 281        $sid,
 282        $configpath,
 283        $roster,
 284        $delim,
 285        $matches,
 286        $defaults
 287        );
 288 
 289     $configpath = SystemVariables::getCourseConfigPath();
 290     $defaults = SystemVariables::getStudentDefaults();
 291 
 292     $roster = $configpath . ".roster";
 293     
 294     open(ROSTER, $roster) ||
 295 	die("Can't open roster for reading");
 296 
 297     #Roster parsing is school dependent; therefore,
 298     # if a different roster is provided, you will
 299     # want to change the parseRosterLine function
 300     # to suit your particular roster.
 301     
 302     while(<ROSTER>) {
 303 	($matches, $username, $lastname, $firstname,
 304 	 $sid, $sectionnumber) = parseRosterLine($_);
 305 	
 306 	######################################
 307 	# RIGHT HERE! If it doesn't match,
 308 	# we have a withdrawn student. They need
 309 	# to be expired right here and now. SO,
 310 	# something needs to be done as an else....
 311 	if($matches) {
 312 
 313 	    $studentdata{"_USERNAME"}      = $username;
 314 	    $studentdata{"_LASTNAME"}      = $lastname;
 315 	    $studentdata{"_FIRSTNAME"}     = $firstname;
 316 	    $studentdata{"_SID"}           = $sid;
 317 	    $studentdata{"_SECTIONNUMBER"} = $sectionnumber;
 318 	    if(defined($$defaults{"_CLASSEXPIRATION"})) {
 319 		$studentdata{"_EXPIRATION"}    = $$defaults{"_CLASSEXPIRATION"};
 320 	    } else {
 321 		$studentdata{"_EXPIRATION"} = "1000,01,01,00:00:00";
 322 	    }
 323 
 324 	    #Don't know if it is safe to plug in defaults here...
 325 	    #foreach $key (keys %{$defaults}) {
 326 	    #$studentdata{$key} = $$defaults{$key};
 327 	    #}
 328 	    
 329 	    createStudent($username, %studentdata);
 330 	}
 331     }
 332 
 333     close(ROSTER);
 334 }
 335 
 336 ##CONTRACT
 337 # parseRosterLine : String -> Array
 338 ##PURPOSE
 339 # Takes a line from the roster, and splits it into
 340 # its component parts. It does this only
 341 # if the line is the _proper_ line, that is,
 342 # one containing valid student data.
 343 #
 344 # If this were to be used for different schools,
 345 # then this function would merely need to
 346 # be rewritten to read the new roster data.
 347 ##DEPENDANCIES
 348 # None.
 349 sub parseRosterLine  {
 350 
 351     my ($line,
 352 	@params,
 353 	$param
 354 	);
 355 
 356     $line = $_[0];
 357     chomp $line;
 358     
 359     #If the line ends with INDIANA.EDU, that 
 360     # is the line we want to grab data from
 361     # The unshift places a 1 or 0 in the first
 362     # field of the returned array
 363     #Fields are
 364     # SessionYear, Campus, Section, SSN, Last, First, Username, INDIANA.EDU
 365     #     0          1        2      3     4      5       6          7
 366     if($line =~ /,INDIANA.EDU(r)*$/) {
 367 	@params = (split(/,/, $line))[6,4,5,3,2];
 368 	
 369 	#IF the student is lacking either
 370 	# A username, or 
 371 	# their username is flagged as **WITHDRAWN**
 372 	# Then you don't want them in the .correllation file, and
 373 	# you don't want a directory created for them.
 374 	#
 375 	# Otherwise, go ahead and create all these good things for
 376 	# the student.
 377 	$tempuname = $params[0];
 378 	$tempuname =~ s/s*//g;
 379 	if( (length($tempuname) < 1) || ($line =~ /WITHDRAWN/i)) {
 380 	    unshift(@params, 0);
 381 	} else {
 382 	    unshift(@params, 1);
 383 	}
 384     }
 385     
 386     #Clean up the params to be passed back
 387     foreach $param (@params) {
 388 	#Only remove leading and trailing spaces
 389 	$param =~ s/^(s+)//g;
 390 	$param =~ s/(s+)$//g;
 391 	$param = lc($param);
 392 	chomp $param;
 393     }
 394     
 395     return @params;
 396 }
 397 
 398 
 399 
 400 
 401 ##CONTRACT
 402 # DEBUG : Array -> Void
 403 ##PURPOSE
 404 # Sends characters to the web browser. 
 405 ##DEPENDANCIES
 406 # None.
 407 sub useDebugging())'>DEBUG { if(SystemVariables::useDebugging())  { print @_, "n<P>"; } }
 408 
 409 return 1;
 410 

Last update: 1/6/01; 9:32:37 AM