File:
[LON-CAPA] /
loncom /
enrollment /
Enrollment.pm
Revision
1.15:
download - view:
text,
annotated -
select for diffs
Thu Jun 17 18:31:24 2004 UTC (20 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Calls to functions in localenroll.pm mediated by lonc/lond now include domain
in the set of passed parameters to support domain-specific variants in a single
localenroll.pm file housed on a multi-domain library server.
Automated enrollment now sets first access and last access dates for student
roles based on defaults set on course creation, and modifiable via a number
of mechanisms in the Enrollment Manager, and Automated Enrollment Manager.
The Automated Enrollment Manager now provides a utility to allow enrollment type
to be toggled between 'auto' and 'manual', so that students added via CSV file
or singly can become liable for automated update (dropping, section switching
etc.).
1: # Automated Enrollment manager
2: # $Id: Enrollment.pm,v 1.15 2004/06/17 18:31:24 raeburn Exp $
3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26: package LONCAPA::Enrollment;
27:
28: use Apache::loncoursedata;
29: use Apache::lonnet;
30: use Apache::lonmsg;
31: use HTML::Entities;
32: use LONCAPA::Configuration;
33: use Time::Local;
34: use lib '/home/httpd/lib/perl';
35: use localenroll;
36:
37: use strict;
38:
39: sub update_LC {
40: my ($dom,$crs,$adds,$drops,$startdate,$enddate,$authtype,$autharg,$classesref,$groupref,$logmsg,$newusermsg,$context) = @_;
41: # Get current LON-CAPA student enrollment for this class
42: my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
43: my $cid = $dom."_".$crs;
44: my $roster = &Apache::loncoursedata::get_classlist($cid,$dom,$crs);
45: my $cend = &Apache::loncoursedata::CL_END;
46: my $cstart = &Apache::loncoursedata::CL_START;
47: my $stuid=&Apache::loncoursedata::CL_ID;
48: my $sec=&Apache::loncoursedata::CL_SECTION;
49: my $status=&Apache::loncoursedata::CL_STATUS;
50: my $type=&Apache::loncoursedata::CL_TYPE;
51: my @localstudents = ();
52: my @futurestudents = ();
53: my @activestudents = ();
54: my $currlist;
55: foreach my $uname (keys %{$roster} ) {
56: if ($uname =~ m/^(.+):$dom$/) {
57: if ($$roster{$uname}[$status] eq "Active") {
58: push @activestudents, $1;
59: @{$$currlist{$1}} = @{$$roster{$uname}};
60: push @localstudents, $1;
61: } elsif ( ($$roster{$uname}[$cstart] > time) && ($$roster{$uname}[$cend] > time || $$roster{$uname}[$cend] == 0 || $$roster{$uname}[$cend] eq '') ) {
62: push @futurestudents, $1;
63: @{$$currlist{$1}} = @{$$roster{$uname}};
64: push @localstudents, $1;
65: }
66: }
67: }
68: my $linefeed = '';
69: my $addresult = '';
70: my $dropresult = '';
71: if ($context eq "updatenow") {
72: $linefeed = "</li>\n<li>";
73: } elsif ($context eq "automated") {
74: $linefeed = "\n";
75: }
76: my $enrollcount = 0;
77: my $dropcount = 0;
78:
79: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand in case initial passwords have to be generated for new users.
80:
81: # Get mapping of IDs to usernames for current LON-CAPA student enrollment for this class
82: my @LCids = ();
83: my %unameFromLCid = ();
84: foreach my $uname (sort keys %{$currlist}) {
85: my $stuID = $$currlist{$uname}[$stuid];
86: if (!grep/^$stuID$/,@LCids) {
87: push @LCids, $stuID;
88: @{$unameFromLCid{$stuID}} = ();
89: }
90: push @{$unameFromLCid{$stuID}},$uname;
91: }
92:
93: # Get latest institutional enrollment for this class.
94: my %allenrolled = ();
95: my @reg_students = ();
96: my %place = ();
97: $place{'autharg'} = &CL_autharg();
98: $place{'authtype'} = &CL_authtype();
99: $place{'email'} = &CL_email();
100: $place{'enddate'} = &CL_enddate();
101: $place{'firstname'} = &CL_firstname();
102: $place{'generation'} = &CL_generation();
103: $place{'groupID'} = &CL_groupID();
104: $place{'lastname'} = &CL_lastname();
105: $place{'middlename'} = &CL_middlename();
106: $place{'startdate'} = &CL_startdate();
107: $place{'studentID'} = &CL_studentID();
108: my %ucount = ();
109: my %enrollinfo = ();
110: foreach my $class (@{$classesref}) {
111: my %enrolled = ();
112: &parse_classlist($$configvars{'lonDaemons'},$dom,$crs,$class,\%place,$$groupref{$class},\%enrolled);
113: foreach my $uname (sort keys %enrolled ) {
114: if (!grep/^$uname$/,@reg_students) {
115: push @reg_students,$uname;
116: $ucount{$uname} = 0;
117: @{$allenrolled{$uname}} = ();
118: }
119: @{$allenrolled{$uname}[$ucount{$uname}]} = @{$enrolled{$uname}};
120: $ucount{$uname} ++;
121: }
122: }
123:
124: # Check for multiple sections for a single student
125: my @okusers = ();
126: foreach my $uname (@reg_students) {
127: if (@{$allenrolled{$uname}} > 1) {
128: my @sections = ();
129: my $saved;
130: for (my $i=0; $i<@{$allenrolled{$uname}}; $i++) {
131: my @stuinfo = @{$allenrolled{$uname}[$i]};
132: my $secnum = $stuinfo[ $place{'groupID'} ];
133: unless ($secnum eq '') {
134: unless (grep/^$secnum$/,@sections) {
135: $saved = $i;
136: push @sections,$secnum;
137: }
138: }
139: }
140: if (@sections == 0) {
141: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
142: push @okusers, $uname;
143: }
144: elsif (@sections == 1) {
145: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[$saved]};
146: push @okusers, $uname;
147: }
148: elsif (@sections > 1) {
149: $$logmsg = "$uname appears in classlists for the more than one section of this course, i.e. in sections: ";
150: foreach (@sections) {
151: $$logmsg .= " $_,";
152: }
153: chop($$logmsg);
154: $$logmsg .= ". Because of this ambiguity, no enrollment action was taken for this student.".$linefeed;
155: }
156: } else {
157: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
158: push @okusers, $uname;
159: }
160: }
161: # Get mapping of student IDs to usernames for users in institutional data for this class
162: my @allINids = ();
163: my %unameFromINid = ();
164: foreach my $uname (@okusers) {
165: $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;
166: my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];
167: if (grep/^$stuID$/,@allINids) {
168: push @{$unameFromINid{$stuID}},$uname;
169: } else {
170: push @allINids, $stuID;
171: @{$unameFromINid{$stuID}} = $uname;
172: }
173: }
174: # Explicitly allow access to creation/modification of students if called as an automated process.
175: if ($context eq 'automated') {
176: $ENV{'allowed.cst'}='F';
177: }
178:
179: # Compare IDs with existing LON-CAPA enrollment for this class
180: foreach my $uname (@okusers) {
181: unless ($uname eq '') {
182: my %uidhash=&Apache::lonnet::idrget($dom,$uname);
183: my @stuinfo = @{$enrollinfo{$uname}};
184: my $access = '';
185: if (grep/^$uname$/,@localstudents) {
186: # Check for studentID changes
187: if ( ($uidhash{$uname}) && ($uidhash{$uname} !~ /error\:/) ) {
188: unless ( ($uidhash{$uname}) eq ($stuinfo[ $place{studentID} ]) ) {
189: $$logmsg .= "Change in ID for $uname. StudentID in LON-CAPA system is $uidhash{$uname}; StudentID in institutional data is $stuinfo[ $place{studentID} ]".$linefeed;
190: }
191: }
192: # Check for section changes
193: if ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) {
194: # Check for access date changes for students with access starting in the future.
195: if ( (grep/^$uname$/,@futurestudents) && ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
196: my $datechange = 0;
197: unless ($$currlist{$uname}[$cstart] eq $startdate) {
198: $datechange = 1;
199: }
200: if (!$datechange) {
201: if (!$$currlist{$uname}[$cend]) {
202: if ($enddate) {
203: $datechange = 1;
204: }
205: } elsif ($$currlist{$uname}[$cend] ne $enddate) {
206: $datechange = 1;
207: }
208: }
209: if ($datechange) {
210: my $modify_access_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto',$cid);
211: $access = &showaccess($enddate,$startdate);
212: if ($modify_access_result =~ /^ok/) {
213: $$logmsg .= "Change in access dates for $uname.".$access.$linefeed;
214: } else {
215: $$logmsg .= "Error when attempting to change start and/or end access dates for $uname in section: ".$stuinfo[ $place{groupID} ]." -error $modify_access_result".$linefeed;
216: }
217: }
218: }
219: } else {
220: if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
221: # Delete from roles.db for current section
222: my $expiretime = time;
223: my $uurl='/'.$cid;
224: $uurl=~s/\_/\//g;
225: if ($$currlist{$uname}[$sec]) {
226: $uurl.='/'.$$currlist{$uname}[$sec];
227: }
228: my $expire_role_result = &Apache::lonnet::assignrole($dom,$uname,$uurl,'st',$expiretime);
229: if ($expire_role_result eq 'ok') {
230: my $modify_section_result;
231: if (grep/^$uname$/,@activestudents) {
232: $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$$currlist{$uname}[$cend],$$currlist{$uname}[$cstart],'auto',$cid);
233: } else {
234: $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto',$cid);
235: $access = &showaccess($enddate,$startdate);
236: }
237: if ($modify_section_result =~ /^ok/) {
238: $$logmsg .= "Section for $uname switched from old section: ".$$currlist{$uname}[$sec] ." to new section: ".$stuinfo[ $place{groupID} ].".".$access.$linefeed;
239: } else {
240: $$logmsg .= "Error when attempting section change for $uname from old section ".$$currlist{$uname}[$sec]." to new section: ".$stuinfo[ $place{groupID} ]." -error: $modify_section_result".$linefeed;
241: }
242: } else {
243: $$logmsg .= "Error when attempting to expire role for $uname in old section" .$$currlist{$uname}[$sec]." -error: $expire_role_result".$linefeed;
244: }
245: }
246: }
247: } else {
248: # Check for changed usernames by checking studentIDs
249: if ( ($stuinfo[ $place{studentID} ] ne '') && (grep/^$stuinfo[ $place{studentID} ]$/,@LCids) ) {
250: if (grep/^$$currlist{$uname}[ $place{'studentID'} ]$/,@allINids) {
251: foreach my $match ( @{ $unameFromLCid{ $stuinfo[ $place{studentID} ] } } ) {
252: if (grep/^$match$/,@okusers) {
253: $$logmsg .= "A possible change in username has been detected for a student enrolled in this course. The existing LON-CAPA classlist contains user: $uname and student ID: ".$$currlist{$uname}[ $place{studentID} ].". This username has been dropped from the institutional classlist, but the same student ID is used for user: $match who still appears in the institutional classlist. You may need to contact your Domain Coordinator to request a move of the student data files for user: $uname to $match".$linefeed;
254: }
255: }
256: }
257: } elsif ($adds == 1) {
258: # Add student to LON-CAPA classlist
259: my $auth = $stuinfo[ $place{'authtype'} ];
260: my $authparam = $stuinfo[ $place{'autharg'} ];
261: my $first = $stuinfo[ $place{'firstname'} ];
262: my $middle = $stuinfo[ $place{'middlename'} ];
263: my $last = $stuinfo[ $place{'lastname'} ];
264: my $gene = $stuinfo[ $place{'generation'} ];
265: my $usec = $stuinfo[ $place{'groupID'} ];
266: my $end = $stuinfo[ $place{'enddate'} ];
267: my $start = $stuinfo[ $place{'startdate'} ];
268: my $emailaddr = $stuinfo[ $place{'email'} ];
269: my $pid = $stuinfo[ $place{'studentID'} ];
270:
271: # remove non alphanumeric values from section
272: $usec =~ s/\W//g;
273:
274: unless ($emailaddr =~/^[^\@]+\@[^\@]+$/) { $emailaddr =''; }
275: my $emailenc = &HTML::Entities::encode($emailaddr,'<>&"');
276:
277: # Use course defaults where entry is absent
278: if ( ($auth eq '') || (!defined($auth)) ) {
279: $auth = $authtype;
280: }
281: if ( ($authparam eq '') || (!defined($authparam)) ) {
282: $authparam = $autharg;
283: }
284: if ( ($end eq '') || (!defined($end)) ) {
285: $end = $enddate;
286: }
287: if ( ($start eq '') || (!defined($start)) ) {
288: $start = $startdate;
289: }
290: # Clean up whitespace
291: foreach (\$dom,\$uname,\$pid,\$first,\$middle,\$last,\$gene,\$usec) {
292: $$_ =~ s/(\s+$|^\s+)//g;
293: }
294:
295: # Check for existing account in this LON-CAPA domain for this username
296: my $uhome=&Apache::lonnet::homeserver($uname,$dom);
297: if ($uhome eq 'no_host') { # User does not exist
298: my $create_passwd = 0;
299: my $authchk = '';
300: unless ($authparam eq '') { $authchk = 'ok'; };
301: # If no account exists and passwords should be generated
302: if ($auth eq "internal") {
303: if ($authparam eq '') {
304: ($authparam) = &create_password();
305: if ($authparam eq '') {
306: $authchk = '';
307: } else {
308: $create_passwd = 1;
309: $authchk = 'ok';
310: }
311: }
312: } elsif ($auth eq "localauth") {
313: ($authparam,$create_passwd,$authchk) = &localenroll::create_password($authparam);
314: } elsif ($auth =~ m/^krb/) {
315: if ($authparam eq '') {
316: $$logmsg .= "No Kerberos domain was provided for the new user - $uname, so the new student was not enrolled in the course.".$linefeed;
317: $authchk = 'invalid';
318: }
319: } else {
320: $authchk = 'invalid';
321: $$logmsg .= "An invalid authentication type was provided for the new user - $uname, so the student was not enrolled in the course.".$linefeed;
322: }
323: if ($authchk eq 'ok') {
324: # Now create user.
325: my $reply=&Apache::lonnet::modifystudent($dom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto',$cid);
326: if ($reply eq 'ok') {
327: $access = &showaccess($end,$start);
328: $enrollcount ++;
329: $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$access.$linefeed;
330: if ($context eq 'automated') {
331: $$logmsg .= "New $dom user $uname added successfully.";
332: }
333: unless ($emailenc eq '') {
334: my %emailHash;
335: $emailHash{'critnotification'} = $emailenc;
336: $emailHash{'notification'} = $emailenc;
337: my $putresult = &Apache::lonnet::put('environment',\%emailHash,$dom,$uname);
338: }
339: if ($create_passwd) {
340: # Send e-mail with initial password to new user at $emailaddr.
341: # If e-mail address is invalid, send password via message to courseowner i
342: # (if automated call) or to user if roster update.
343: if ($emailaddr eq '') {
344: $$newusermsg .= " username: $uname, password: ".$authparam.$linefeed."\n";
345: } else {
346: my $subject = "New LON-CAPA account";
347: my $body = "You have been enrolled in the LON-CAPA system at your school, because you are a registered student in a class that is using the LON-CAPA course management and online homework system.\n\nYou should log-in to the system using the following credentials:\nusername: $uname\npassword: $authparam\n\nThe URL you should use to access the LON-CAPA system at your school is: http://".$ENV{'SERVER_NAME'};
348: &Apache::lonmsg::sendemail($emailaddr,$subject,$body);
349: }
350: if ($context eq 'automated') {
351: $$logmsg .= " Initial password - - sent to ".$emailaddr.$linefeed;
352: }
353: } else {
354: if ($context eq 'automated') {
355: $$logmsg .= $linefeed;
356: }
357: }
358: } else {
359: $$logmsg .= "An error occurred adding new user $uname - ".$reply.$linefeed;
360: }
361: }
362: } else {
363: # Get the user's information and authentication
364: my %userenv = &Apache::lonnet::get('environment',['firstname','middlename','lastname','generation','id','critnotification','notification'],$dom,$uname);
365: my ($tmp) = keys(%userenv);
366: if ($tmp =~ /^(con_lost|error)/i) {
367: %userenv = ();
368: }
369: # Get the user's e-mail address
370: if ($userenv{critnotification} =~ m/%40/) {
371: unless ($emailenc eq $userenv{critnotification}) {
372: $$logmsg .= "Current critical notification e-mail - ".$userenv{critnotification}." for $uname is different to e-mail address in Institutional classlist - ".$emailenc.$linefeed;
373: }
374: }
375: if ($userenv{notification} =~ m/%40/) {
376: unless ($emailenc eq $userenv{critnotification}) {
377: $$logmsg .= "Current standard notification e-mail - ".$userenv{notification}." for $uname is different to e-mail address in institutional classlist - ".$emailenc.$linefeed;
378: }
379: }
380: my $krbdefdom = '';
381: my $currentauth=&Apache::lonnet::queryauthenticate($uname,$dom);
382: if ($currentauth=~/^(krb[45]):(.*)/) {
383: $currentauth = $1;
384: $krbdefdom = $2;
385: } elsif ($currentauth=~ /^(unix|internal|localauth):/) {
386: $currentauth = $1;
387: } else {
388: $$logmsg .= "Invalid authentication method $currentauth for $uname.".$linefeed;
389: }
390: # Report if authentication methods are different.
391: if ($currentauth ne $auth) {
392: $$logmsg .= "Authentication type mismatch for $uname - '$currentauth' in system, '$auth' based on information in classlist or default for this course.".$linefeed;
393: } elsif ($auth =~ m/^krb/) {
394: if ($krbdefdom ne $authparam) {
395: $$logmsg .= "Kerberos domain mismatch for $uname - '$krbdefdom' in system, '$authparam' based on information in classlist or default for this course.".$linefeed;
396: }
397: }
398:
399: # Check user data
400: if ($first ne $userenv{'firstname'} ||
401: $middle ne $userenv{'middlename'} ||
402: $last ne $userenv{'lastname'} ||
403: $gene ne $userenv{'generation'} ||
404: $pid ne $userenv{'id'} ) {
405: # Make the change(s)
406: my %changeHash;
407: $changeHash{'firstname'} = $first;
408: $changeHash{'middlename'} = $middle;
409: $changeHash{'lastname'} = $last;
410: $changeHash{'generation'} = $gene;
411: $changeHash{'id'} = $pid;
412: my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);
413: if ($putresult eq 'ok') {
414: $$logmsg .= "User information updated for user: $uname prior to enrollment.".$linefeed;
415: } else {
416: $$logmsg .= "There was a problem modifying user data for existing user - $uname -error: $putresult, enrollment will still be attempted.".$linefeed;
417: }
418: }
419:
420: # Assign the role of student in the course.
421: my $classlist_reply = &Apache::lonnet::modify_student_enrollment($dom,$uname,$pid,$first,$middle,$last,$gene,$usec,$end,$start,'auto',$cid);
422: if ($classlist_reply eq 'ok') {
423: $access = &showaccess($end,$start);
424: $enrollcount ++;
425: $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$access.$linefeed;
426: if ($context eq 'automated') {
427: $$logmsg .= "Existing $dom user $uname enrolled successfully.".$linefeed;
428: }
429: } else {
430: $$logmsg .= "There was a problem updating the classlist db file for user $uname to show the new enrollment -error: $classlist_reply, so no enrollment occurred for this user.".$linefeed;
431: }
432: }
433: }
434: }
435: }
436: }
437: # Do drops
438: if ( ($drops == 1) && (@reg_students > 0) ) {
439: foreach my $uname (@localstudents) {
440: if ($$currlist{$uname}[$type] eq "auto") {
441: my @saved = ();
442: if (!grep/^$uname$/,@reg_students) {
443: # Check for changed usernames by checking studentIDs
444: if (grep/^$$currlist{$uname}[ $stuid ]$/,@allINids) {
445: foreach my $match (@{$unameFromINid{$$currlist{$uname}[ $stuid ]}} ) {
446: $$logmsg .= "A possible change in username has been detected for a student enrolled in this course. The existing LON-CAPA classlist contains user: $uname and student ID: $$currlist{$uname}[ $place{studentID} ]. This username has been dropped from the institutional classlist, but the same student ID is used for user: $match who still appears in the institutional classlist. You may need to move the student data files for user: $uname to $match.".$linefeed;
447: push @saved,$uname;
448: }
449: } elsif (@saved == 0) {
450: my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto',$cid);
451: if ($drop_reply !~ /^ok/) {
452: $$logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $drop_reply.".$linefeed;
453: } else {
454: $dropcount ++;
455: my %userenv = &Apache::lonnet::get('environment',['firstname','lastname','id'],$dom,$uname);
456: $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname." dropped from section/group ".$$currlist{$uname}[$sec].$linefeed;
457: if ($context eq 'automated') {
458: $$logmsg .= "User $uname student role expired from course.".$linefeed;
459: }
460: }
461: }
462: }
463: }
464: }
465: }
466:
467: # Terminated explictly allowed access to student creation/modification
468: if ($context eq 'automated') {
469: delete($ENV{'allowed.cst'});
470: }
471: if ($enrollcount > 0) {
472: if ($context eq "updatenow") {
473: $addresult = substr($addresult,0,rindex($addresult,"<li>"));
474: $addresult = "The following $enrollcount student(s) was/were added to this LON-CAPA course:<br/><ul><li>".$addresult."</li></ul><br/><br/>";
475: } else {
476: $addresult = "The following $enrollcount student(s) was/were added to this LON-CAPA course:\n\n".$addresult."\n\n";
477: }
478: }
479: if ($dropcount > 0) {
480: if ($context eq "updatenow") {
481: $dropresult = substr($dropresult,0,rindex($dropresult,"<li>"));
482: $dropresult = "The following $dropcount student(s) was/were expired from this LON-CAPA course:<br/><ul><li>".$dropresult."</li></ul><br/><br/>";
483: } else {
484: $dropresult = "The following $dropcount student(s) was/were expired from this LON-CAPA course:\n\n".$dropresult."\n\n";
485: }
486: }
487: if ( ($adds) && ($enrollcount == 0) ) {
488: $addresult = "There were no new students to add to the course.";
489: if ($context eq "updatenow") {
490: $addresult .="<br/><br/>";
491: } else {
492: $addresult .="\n";
493: }
494: }
495: if ( ($drops) && ($dropcount == 0) ) {
496: $dropresult = "There were no students with roles to expire because all active students previously added to the course from institutional classlist(s) are still officially registered.";
497: if ($context eq "updatenow") {
498: $dropresult .="<br/>";
499: } else {
500: $dropresult .="\n";
501: }
502: }
503: my $changecount = $enrollcount + $dropcount;
504: return ($changecount,$addresult.$dropresult);
505: }
506:
507: sub showaccess {
508: my ($end,$start) = @_;
509: my $showstart;
510: my $showend;
511: if ( (!$start) || ($start <= time) ) {
512: $showstart = 'immediately';
513: } else {
514: $showstart = &Apache::lonlocal::locallocaltime($start);
515: }
516: if (!$end) {
517: $showend = 'no end date';
518: } else {
519: $showend = &Apache::lonlocal::locallocaltime($end);
520: }
521: my $access_msg = " Access starts: ".$showstart.", ends: ".$showend.".";
522: return $access_msg;
523: }
524:
525: sub parse_classlist {
526: my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;
527: my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_".$class."_classlist.xml";
528: my $uname = '';
529: my @state;
530: my @items = ('autharg','authtype','email','firstname','generation','lastname','middlename','studentID');
531: my $p = HTML::Parser->new
532: (
533: xml_mode => 1,
534: start_h =>
535: [sub {
536: my ($tagname, $attr) = @_;
537: push @state, $tagname;
538: if ("@state" eq "students student") {
539: $uname = $attr->{username};
540: }
541: }, "tagname, attr"],
542: text_h =>
543: [sub {
544: my ($text) = @_;
545: if ("@state" eq "students student groupID") {
546: $$studentsref{$uname}[ $$placeref{'groupID'} ] = $groupID;
547: } elsif ("@state" eq "students student startdate") {
548: my $start = $text;
549: unless ($text eq '') {
550: $start = &process_date($text);
551: }
552: $$studentsref{$uname}[ $$placeref{'startdate'} ] = $start;
553: } elsif ("@state" eq "students student enddate") {
554: my $end = $text;
555: unless ($text eq '') {
556: $end = &process_date($text);
557: }
558: $$studentsref{$uname}[ $$placeref{'enddate'} ] = $end;
559: } else {
560: foreach my $item (@items) {
561: if ("@state" eq "students student $item") {
562: $$studentsref{$uname}[ $$placeref{$item} ] = $text;
563: }
564: }
565: }
566: }, "dtext"],
567: end_h =>
568: [sub {
569: my ($tagname) = @_;
570: pop @state;
571: }, "tagname"],
572: );
573:
574: $p->parse_file($xmlfile);
575: $p->eof;
576: if (-e "$xmlfile") {
577: unlink $xmlfile;
578: }
579: return;
580: }
581:
582: sub process_date {
583: my $timestr = shift;
584: my $timestamp = '';
585: if ($timestr =~ m/^\d{4}:\d{2}:\d{2}/) {
586: my @entries = split/:/,$timestr;
587: for (my $j=0; $j<@entries; $j++) {
588: if ( length($entries[$j]) > 1 ) {
589: $entries[$j] =~ s/^0//;
590: }
591: }
592: $entries[1] = $entries[1] - 1;
593: $timestamp = timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]);
594: }
595: return $timestamp;
596: }
597:
598: sub create_password {
599: my $passwd = '';
600: my @letts = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
601: for (my $i=0; $i<8; $i++) {
602: my $lettnum = int (rand 2);
603: my $item = '';
604: if ($lettnum) {
605: $item = $letts[int( rand(26) )];
606: my $uppercase = int(rand 2);
607: if ($uppercase) {
608: $item =~ tr/a-z/A-Z/;
609: }
610: } else {
611: $item = int( rand(10) );
612: }
613: $passwd .= $item;
614: }
615: return ($passwd);
616: }
617:
618: sub check_user_status {
619: my ($udom,$uname,$cdom,$crs,$role,$secgrp) = @_;
620: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
621: my @uroles = keys %userinfo;
622: my $srchstr;
623: my $active_chk = 'none';
624: if (@uroles > 0) {
625: if ( ($role eq 'cc') || ($secgrp eq '') || ( !defined($secgrp) ) ) {
626: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
627: } else {
628: $srchstr = '/'.$cdom.'/'.$crs.'/'.$secgrp.'_'.$role;
629: }
630: if (grep/^$srchstr$/,@uroles) {
631: my $role_end = 0;
632: my $role_start = 0;
633: $active_chk = 'ok';
634: if ( $userinfo{$srchstr} =~ m/^($role)_(\d+)/ ) {
635: $role_end = $2;
636: if ( $userinfo{$srchstr} =~ m/^($role)_($role_end)_(\d+)$/ )
637: {
638: $role_start = $3;
639: }
640: }
641: if ($role_start > 0) {
642: if (time < $role_start) {
643: $active_chk = 'expired';
644: }
645: }
646: if ($role_end > 0) {
647: if (time > $role_end) {
648: $active_chk = 'expired';
649: }
650: }
651: }
652: }
653: return $active_chk;
654: }
655:
656: sub CL_autharg { return 0; }
657: sub CL_authtype { return 1;}
658: sub CL_email { return 2;}
659: sub CL_enddate { return 3;}
660: sub CL_firstname { return 4;}
661: sub CL_generation { return 5;}
662: sub CL_groupID { return 6;}
663: sub CL_lastname { return 7;}
664: sub CL_middlename { return 8;}
665: sub CL_startdate { return 9; }
666: sub CL_studentID { return 10; }
667:
668: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>