File:
[LON-CAPA] /
loncom /
enrollment /
Enrollment.pm
Revision
1.9:
download - view:
text,
annotated -
select for diffs
Mon Dec 15 05:39:40 2003 UTC (20 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Added check_user_status subroutine. Used to determine if a course coordinator role is active in a course. Used by lonpopulate.pm when building the notification display table. Avoids the problem of stale end dates in the nohist_userroles table for the course.
1: # Automated Enrollment manager
2: # $Id: Enrollment.pm,v 1.9 2003/12/15 05:39:40 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 $currlist;
53: foreach my $uname (keys %{$roster} ) {
54: if ($uname =~ m/^(.+):$dom$/) {
55: if ($$roster{$uname}[$status] eq "Active") {
56: push @localstudents, $1;
57: @{$$currlist{$1}} = @{$$roster{$uname}};
58: }
59: }
60: }
61: my $linefeed = '';
62: my $addresult = '';
63: my $dropresult = '';
64: if ($context eq "updatenow") {
65: $linefeed = "</li>\n<li>";
66: } elsif ($context eq "automated") {
67: $linefeed = "\n";
68: }
69: my $enrollcount = 0;
70: my $dropcount = 0;
71:
72: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand in case initial passwords have to be generated for new users.
73:
74: # Get mapping of IDs to usernames for current LON-CAPA student enrollment for this class
75: my @LCids = ();
76: my %unameFromLCid = ();
77: foreach my $uname (sort keys %{$currlist}) {
78: my $stuID = $$currlist{$uname}[$stuid];
79: if (!grep/^$stuID$/,@LCids) {
80: push @LCids, $stuID;
81: @{$unameFromLCid{$stuID}} = ();
82: }
83: push @{$unameFromLCid{$stuID}},$uname;
84: }
85:
86: # Get latest institutional enrollment for this class.
87: my %allenrolled = ();
88: my @reg_students = ();
89: my %place = ();
90: $place{'autharg'} = &CL_autharg();
91: $place{'authtype'} = &CL_authtype();
92: $place{'email'} = &CL_email();
93: $place{'enddate'} = &CL_enddate();
94: $place{'firstname'} = &CL_firstname();
95: $place{'generation'} = &CL_generation();
96: $place{'groupID'} = &CL_groupID();
97: $place{'lastname'} = &CL_lastname();
98: $place{'middlename'} = &CL_middlename();
99: $place{'startdate'} = &CL_startdate();
100: $place{'studentID'} = &CL_studentID();
101: my %ucount = ();
102: my %enrollinfo = ();
103: foreach my $class (@{$classesref}) {
104: my %enrolled = ();
105: &parse_classlist($$configvars{'lonDaemons'},$dom,$crs,$class,\%place,$$groupref{$class},\%enrolled);
106: foreach my $uname (sort keys %enrolled ) {
107: if (!grep/^$uname$/,@reg_students) {
108: push @reg_students,$uname;
109: $ucount{$uname} = 0;
110: @{$allenrolled{$uname}} = ();
111: }
112: @{$allenrolled{$uname}[$ucount{$uname}]} = @{$enrolled{$uname}};
113: $ucount{$uname} ++;
114: }
115: }
116:
117: # Check for multiple sections for a single student
118: my @okusers = ();
119: foreach my $uname (@reg_students) {
120: if (@{$allenrolled{$uname}} > 1) {
121: my @sections = ();
122: my $saved;
123: for (my $i=0; $i<@{$allenrolled{$uname}}; $i++) {
124: my @stuinfo = @{$allenrolled{$uname}[$i]};
125: my $secnum = $stuinfo[ $place{'groupID'} ];
126: unless ($secnum eq '') {
127: unless (grep/^$secnum$/,@sections) {
128: $saved = $i;
129: push @sections,$secnum;
130: }
131: }
132: }
133: if (@sections == 0) {
134: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
135: push @okusers, $uname;
136: }
137: elsif (@sections == 1) {
138: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[$saved]};
139: push @okusers, $uname;
140: }
141: elsif (@sections > 1) {
142: $$logmsg = "$uname appears in classlists for the more than one section of this course, i.e. in sections: ";
143: foreach (@sections) {
144: $$logmsg .= " $_,";
145: }
146: chop($$logmsg);
147: $$logmsg .= ". Because of this ambiguity, no enrollment action was taken for this student.".$linefeed;
148: }
149: } else {
150: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
151: push @okusers, $uname;
152: }
153: }
154: # Get mapping of student IDs to usernames for users in institutional data for this class
155: my @allINids = ();
156: my %unameFromINid = ();
157: foreach my $uname (@okusers) {
158: $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;
159: my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];
160: if (grep/^$stuID$/,@allINids) {
161: push @{$unameFromINid{$stuID}},$uname;
162: } else {
163: push @allINids, $stuID;
164: @{$unameFromINid{$stuID}} = $uname;
165: }
166: }
167: # Explicitly allow access to creation/modification of students if called as an automated process.
168: if ($context eq 'automated') {
169: $ENV{'allowed.cst'}='F';
170: }
171:
172: # Compare IDs with existing LON-CAPA enrollment for this class
173: foreach my $uname (@okusers) {
174: unless ($uname eq '') {
175: my %uidhash=&Apache::lonnet::idrget($dom,$uname);
176: my @stuinfo = @{$enrollinfo{$uname}};
177: if (grep/^$uname$/,@localstudents) {
178: # Check for studentID changes
179: if ( ($uidhash{$uname}) && ($uidhash{$uname} !~ /error\:/) ) {
180: unless ( ($uidhash{$uname}) eq ($stuinfo[ $place{studentID} ]) ) {
181: $$logmsg .= "Change in ID for $uname. StudentID in LON-CAPA system is $uidhash{$uname}; StudentID in institutional data is $stuinfo[ $place{studentID} ]".$linefeed;
182: }
183: }
184:
185: # Check for section changes
186: unless ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) {
187: if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
188: my $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);
189: if ($modify_section_result =~ /^ok/) {
190: $$logmsg .= "Section for $uname switched from old section: ".$$currlist{$uname}[$sec] ." to new section: ".$stuinfo[ $place{groupID} ].".".$linefeed;
191: } else {
192: $$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;
193: }
194: }
195: }
196: } else {
197: # Check for changed usernames by checking studentIDs
198: if ( ($stuinfo[ $place{studentID} ] ne '') && (grep/^$stuinfo[ $place{studentID} ]$/,@LCids) ) {
199: if (grep/^$$currlist{$uname}[ $place{'studentID'} ]$/,@allINids) {
200: foreach my $match ( @{ $unameFromLCid{ $stuinfo[ $place{studentID} ] } } ) {
201: if (grep/^$match$/,@okusers) {
202: $$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;
203: }
204: }
205: }
206: } elsif ($adds == 1) {
207: # Add student to LON-CAPA classlist
208: my $auth = $stuinfo[ $place{'authtype'} ];
209: my $authparam = $stuinfo[ $place{'autharg'} ];
210: my $first = $stuinfo[ $place{'firstname'} ];
211: my $middle = $stuinfo[ $place{'middlename'} ];
212: my $last = $stuinfo[ $place{'lastname'} ];
213: my $gene = $stuinfo[ $place{'generation'} ];
214: my $usec = $stuinfo[ $place{'groupID'} ];
215: my $end = $stuinfo[ $place{'enddate'} ];
216: my $start = $stuinfo[ $place{'startdate'} ];
217: my $emailaddr = $stuinfo[ $place{'email'} ];
218: my $pid = $stuinfo[ $place{'studentID'} ];
219:
220: # remove non alphanumeric values from section
221: $usec =~ s/\W//g;
222:
223: unless ($emailaddr =~/^[^\@]+\@[^\@]+$/) { $emailaddr =''; }
224: my $emailenc = &HTML::Entities::encode($emailaddr);
225:
226: # Use course defaults where entry is absent
227: if ( ($auth eq '') || (!defined($auth)) ) {
228: $auth = $authtype;
229: }
230: if ( ($authparam eq '') || (!defined($authparam)) ) {
231: $authparam = $autharg;
232: }
233: if ($auth =~ m/^krb/) {
234: $auth .= ":".$authparam;
235: }
236: if ( ($end eq '') || (!defined($end)) ) {
237: $end = $enddate;
238: }
239: if ( ($start eq '') || (!defined($start)) ) {
240: $start = $startdate;
241: }
242: # Clean up whitespace
243: foreach (\$dom,\$uname,\$pid,\$first,\$middle,\$last,\$gene,\$usec) {
244: $$_ =~ s/(\s+$|^\s+)//g;
245: }
246:
247: # Check for existing account in this LON-CAPA domain for this username
248: my $uhome=&Apache::lonnet::homeserver($uname,$dom);
249: if ($uhome eq 'no_host') { # User does not exist
250: my $create_passwd = 0;
251: my $authchk = '';
252: unless ($authparam eq '') { $authchk = 'ok'; };
253: # If no account exists and passwords should be generated
254: if ($authtype eq "int") {
255: if ($authparam eq '') {
256: ($authparam) = &create_password();
257: if ($authparam eq '') {
258: $authchk = '';
259: } else {
260: $create_passwd = 1;
261: }
262: }
263: } elsif ($authtype eq "local") {
264: ($authparam,$create_passwd,$authchk) = &localenroll::create_password($authparam);
265: } elsif ($authtype =~ m/^krb/) {
266: if ($authparam eq '') {
267: $$logmsg .= "No Kerberos domain was provided for the new user - $uname, so the new student was not enrolled in the course.".$linefeed;
268: $authchk = 'invalid';
269: }
270: } else {
271: $authchk = 'invalid';
272: $$logmsg .= "An invalid authentication type was provided for the new user - $uname, so the student was not enrolled in the course.".$linefeed;
273: }
274: if ($authchk eq 'ok') {
275: # Now create user.
276: my $reply=&Apache::lonnet::modifystudent($dom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto',$cid);
277: if ($reply eq 'ok') {
278: $enrollcount ++;
279: $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
280: if ($context eq 'automated') {
281: $$logmsg .= "New $dom user $uname added successfully.";
282: }
283: unless ($emailenc eq '') {
284: my %emailHash;
285: $emailHash{'critnotification'} = $emailenc;
286: $emailHash{'notification'} = $emailenc;
287: my $putresult = &Apache::lonnet::put('environment',\%emailHash,$dom,$uname);
288: }
289: if ($create_passwd) {
290: # Send e-mail with initial password to new user at $emailaddr.
291: # If e-mail address is invalid, send password via message to courseowner i
292: # (if automated call) or to user if roster update.
293: if ($emailaddr eq '') {
294: $$newusermsg .= " username: $uname, password: ".$authparam.$linefeed."\n";
295: } else {
296: my $subject = "New LON-CAPA account";
297: 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'};
298: &Apache::lonmsg::sendemail($emailaddr,$subject,$body);
299: }
300: if ($context eq 'automated') {
301: $$logmsg .= " Initial password - - sent to ".$emailaddr.$linefeed;
302: }
303: } else {
304: if ($context eq 'automated') {
305: $$logmsg .= $linefeed;
306: }
307: }
308: } else {
309: $$logmsg .= "An error occurred adding new user $uname - ".$reply.$linefeed;
310: }
311: }
312: } else {
313: # Get the user's information and authentication
314: my %userenv = &Apache::lonnet::get('environment',['firstname','middlename','lastname','generation','id','critnotification','notification'],$dom,$uname);
315: my ($tmp) = keys(%userenv);
316: if ($tmp =~ /^(con_lost|error)/i) {
317: %userenv = ();
318: }
319: # Get the user's e-mail address
320: if ($userenv{critnotification} =~ m/%40/) {
321: unless ($emailenc eq $userenv{critnotification}) {
322: $$logmsg .= "Current critical notification e-mail - ".$userenv{critnotification}." for $uname is different to e-mail address in Institutional classlist - ".$emailenc.$linefeed;
323: }
324: }
325: if ($userenv{notification} =~ m/%40/) {
326: unless ($emailenc eq $userenv{critnotification}) {
327: $$logmsg .= "Current standard notification e-mail - ".$userenv{notification}." for $uname is different to e-mail address in institutional classlist - ".$emailenc.$linefeed;
328: }
329: }
330: my $krbdefdom = '';
331: my $currentauth=&Apache::lonnet::queryauthenticate($uname,$dom);
332: if ($currentauth=~/^krb(4|5):/) {
333: $currentauth=~/^krb(4|5):(.*)/;
334: $krbdefdom=$1;
335: }
336: if ($currentauth=~/^krb(4|5):/ ||
337: $currentauth=~/^unix:/ ||
338: $currentauth=~/^internal:/ ||
339: $currentauth=~/^localauth:/) {
340:
341: } else {
342: $$logmsg .= "Invalid authentication method $currentauth for $uname.".$linefeed;
343: }
344: # Report if authentication methods are different.
345: if ($currentauth ne $auth ) {
346: $$logmsg .= "Authentication mismatch for $uname - $currentauth in system, $auth based on information in classlist or default for this course.".$linefeed;
347: }
348: # Check user data
349: if ($first ne $userenv{'firstname'} ||
350: $middle ne $userenv{'middlename'} ||
351: $last ne $userenv{'lastname'} ||
352: $gene ne $userenv{'generation'} ||
353: $pid ne $userenv{'id'} ) {
354: # Make the change(s)
355: my %changeHash;
356: $changeHash{'firstname'} = $first;
357: $changeHash{'middlename'} = $middle;
358: $changeHash{'lastname'} = $last;
359: $changeHash{'generation'} = $gene;
360: $changeHash{'id'} = $pid;
361: my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);
362: if ($putresult eq 'ok') {
363: $$logmsg .= "User information updated for user: $uname prior to enrollment.".$linefeed;
364: } else {
365: $$logmsg .= "There was a problem modifying user data for existing user - $uname -error: $putresult, enrollment will still be attempted.".$linefeed;
366: }
367: }
368:
369: # Assign the role of student in the course.
370: my $classlist_reply = &Apache::lonnet::modify_student_enrollment($dom,$uname,$pid,$first,$middle,$last,$gene,$usec,$end,$start,'auto',$cid);
371: if ($classlist_reply eq 'ok') {
372: $enrollcount ++;
373: $addresult .= "$first $last ($pid) - $uname enrolled in section/group $usec.".$linefeed;
374: if ($context eq 'automated') {
375: $$logmsg .= "Existing $dom user $uname enrolled successfully.".$linefeed;
376: }
377: } else {
378: $$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;
379: }
380: }
381: }
382: }
383: }
384: }
385: # Do drops
386: if ( ($drops == 1) && (@reg_students > 0) ) {
387: foreach my $uname (@localstudents) {
388: if ($$currlist{$uname}[$type] eq "auto") {
389: my @saved = ();
390: if (!grep/^$uname$/,@reg_students) {
391: # Check for changed usernames by checking studentIDs
392: if (grep/^$$currlist{$uname}[ $stuid ]$/,@allINids) {
393: foreach my $match (@{$unameFromINid{$$currlist{$uname}[ $stuid ]}} ) {
394: $$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;
395: push @saved,$uname;
396: }
397: } elsif (@saved == 0) {
398: my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,undef,$cid);
399: if ($drop_reply !~ /^ok/) {
400: $$logmsg .= "An error occured during the attempt to expire the $uname from the old section $$currlist{$uname}[$sec] - $drop_reply.".$linefeed;
401: } else {
402: $dropcount ++;
403: my %userenv = &Apache::lonnet::get('environment',['firstname','lastname','id'],$dom,$uname);
404: $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname." dropped from section/group ".$$currlist{$uname}[$sec].$linefeed;
405: if ($context eq 'automated') {
406: $$logmsg .= "User $uname student role expired from course.".$linefeed;
407: }
408: }
409: }
410: }
411: }
412: }
413: }
414:
415: # Terminated explictly allowed access to student creation/modification
416: if ($context eq 'automated') {
417: delete($ENV{'allowed.cst'});
418: }
419: if ($enrollcount > 0) {
420: if ($context eq "updatenow") {
421: $addresult = substr($addresult,0,rindex($addresult,"<li>"));
422: $addresult = "The following $enrollcount student(s) was/were added to this LON-CAPA course:<br/><ul><li>".$addresult."</li></ul><br/><br/>";
423: } else {
424: $addresult = "The following $enrollcount student(s) was/were added to this LON-CAPA course:\n\n".$addresult."\n\n";
425: }
426: }
427: if ($dropcount > 0) {
428: if ($context eq "updatenow") {
429: $dropresult = substr($dropresult,0,rindex($dropresult,"<li>"));
430: $dropresult = "The following $dropcount student(s) was/were expired from this LON-CAPA course:<br/><ul><li>".$dropresult."</li></ul><br/><br/>";
431: } else {
432: $dropresult = "The following $dropcount student(s) was/were expired from this LON-CAPA course:\n\n".$dropresult."\n\n";
433: }
434: }
435: if ( ($adds) && ($enrollcount == 0) ) {
436: $addresult = "There were no new students to add to the course.";
437: if ($context eq "updatenow") {
438: $addresult .="<br/><br/>";
439: } else {
440: $addresult .="\n";
441: }
442: }
443: if ( ($drops) && ($dropcount == 0) ) {
444: $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.";
445: if ($context eq "updatenow") {
446: $dropresult .="<br/>";
447: } else {
448: $dropresult .="\n";
449: }
450: }
451: my $changecount = $enrollcount + $dropcount;
452: return ($changecount,$addresult.$dropresult);
453: }
454:
455: sub parse_classlist {
456: my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;
457: my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_".$class."_classlist.xml";
458: my $uname = '';
459: my @state;
460: my @items = ('autharg','authtype','email','firstname','generation','lastname','middlename','studentID');
461: my $p = HTML::Parser->new
462: (
463: xml_mode => 1,
464: start_h =>
465: [sub {
466: my ($tagname, $attr) = @_;
467: push @state, $tagname;
468: if ("@state" eq "students student") {
469: $uname = $attr->{username};
470: }
471: }, "tagname, attr"],
472: text_h =>
473: [sub {
474: my ($text) = @_;
475: if ("@state" eq "students student groupID") {
476: $$studentsref{$uname}[ $$placeref{'groupID'} ] = $groupID;
477: } elsif ("@state" eq "students student startdate") {
478: my $start = $text;
479: unless ($text eq '') {
480: $start = &process_date($text);
481: }
482: $$studentsref{$uname}[ $$placeref{'startdate'} ] = $start;
483: } elsif ("@state" eq "students student enddate") {
484: my $end = $text;
485: unless ($text eq '') {
486: $end = &process_date($text);
487: }
488: $$studentsref{$uname}[ $$placeref{'enddate'} ] = $end;
489: } else {
490: foreach my $item (@items) {
491: if ("@state" eq "students student $item") {
492: $$studentsref{$uname}[ $$placeref{$item} ] = $text;
493: }
494: }
495: }
496: }, "dtext"],
497: end_h =>
498: [sub {
499: my ($tagname) = @_;
500: pop @state;
501: }, "tagname"],
502: );
503:
504: $p->parse_file($xmlfile);
505: $p->eof;
506: if (-e "$xmlfile") {
507: unlink $xmlfile;
508: }
509: return;
510: }
511:
512: sub process_date {
513: my $timestr = shift;
514: my $timestamp = '';
515: if ($timestr =~ m/^\d{4}:\d{2}:\d{2}/) {
516: my @entries = split/:/,$timestr;
517: for (my $j=0; $j<@entries; $j++) {
518: if ( length($entries[$j]) > 1 ) {
519: $entries[$j] =~ s/^0//;
520: }
521: }
522: $entries[1] = $entries[1] - 1;
523: $timestamp = timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]);
524: }
525: return $timestamp;
526: }
527:
528: sub create_password {
529: my $passwd = '';
530: 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";
531: for (my $i=0; $i<8; $i++) {
532: my $lettnum = int (rand 2);
533: my $item = '';
534: if ($lettnum) {
535: $item = $letts[int( rand(26) )];
536: my $uppercase = int(rand 2);
537: if ($uppercase) {
538: $item =~ tr/a-z/A-Z/;
539: }
540: } else {
541: $item = int( rand(10) );
542: }
543: $passwd .= $item;
544: }
545: return ($passwd);
546: }
547:
548: sub check_user_status {
549: my ($udom,$uname,$cdom,$crs,$role,$secgrp) = @_;
550: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
551: my @uroles = keys %userinfo;
552: my $srchstr;
553: my $active_chk = 'none';
554: if (@uroles > 0) {
555: if ( ($role eq 'cc') || ($secgrp eq '') || ( !defined($secgrp) ) ) {
556: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
557: } else {
558: $srchstr = '/'.$cdom.'/'.$crs.'/'.$secgrp.'_'.$role;
559: }
560: if (grep/^$srchstr$/,@uroles) {
561: my $role_end = 0;
562: my $role_start = 0;
563: $active_chk = 'ok';
564: if ( $userinfo{$srchstr} =~ m/^($role)_(\d+)/ ) {
565: $role_end = $2;
566: if ( $userinfo{$srchstr} =~ m/^($role)_($role_end)_(\d+)$/ )
567: {
568: $role_start = $3;
569: }
570: }
571: if ($role_start > 0) {
572: if (time < $role_start) {
573: $active_chk = 'expired';
574: }
575: }
576: if ($role_end > 0) {
577: if (time > $role_end) {
578: $active_chk = 'expired';
579: }
580: }
581: }
582: }
583: return $active_chk;
584: }
585:
586: sub CL_autharg { return 0; }
587: sub CL_authtype { return 1;}
588: sub CL_email { return 2;}
589: sub CL_enddate { return 3;}
590: sub CL_firstname { return 4;}
591: sub CL_generation { return 5;}
592: sub CL_groupID { return 6;}
593: sub CL_lastname { return 7;}
594: sub CL_middlename { return 8;}
595: sub CL_startdate { return 9; }
596: sub CL_studentID { return 10; }
597:
598: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>