Annotation of loncom/enrollment/Enrollment.pm, revision 1.44
1.7 albertel 1: # Automated Enrollment manager
1.44 ! raeburn 2: # $Id: Enrollment.pm,v 1.43 2010/08/20 21:44:59 raeburn Exp $
1.7 albertel 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: #
1.1 raeburn 26: package LONCAPA::Enrollment;
27:
28: use Apache::loncoursedata;
29: use Apache::lonnet;
1.32 albertel 30: use Apache::loncommon();
1.8 raeburn 31: use Apache::lonmsg;
1.28 raeburn 32: use Apache::lonlocal;
1.1 raeburn 33: use HTML::Entities;
34: use LONCAPA::Configuration;
1.8 raeburn 35: use Time::Local;
36: use lib '/home/httpd/lib/perl';
1.1 raeburn 37:
38: use strict;
39:
40: sub update_LC {
1.44 ! raeburn 41: my ($dom,$crs,$adds,$drops,$startdate,$enddate,$authtype,$autharg,
! 42: $showcredits,$defaultcredits,$classesref,$groupref,$logmsg,$newusermsg,
! 43: $context,$phototypes) = @_;
1.19 raeburn 44: # Get institutional code and title of this class
45: my %courseinfo = ();
46: &get_courseinfo($dom,$crs,\%courseinfo);
1.1 raeburn 47: # Get current LON-CAPA student enrollment for this class
48: my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
49: my $cid = $dom."_".$crs;
1.26 raeburn 50: my $roster = &Apache::loncoursedata::get_classlist($dom,$crs);
1.1 raeburn 51: my $cend = &Apache::loncoursedata::CL_END;
52: my $cstart = &Apache::loncoursedata::CL_START;
53: my $stuid=&Apache::loncoursedata::CL_ID;
54: my $sec=&Apache::loncoursedata::CL_SECTION;
55: my $status=&Apache::loncoursedata::CL_STATUS;
56: my $type=&Apache::loncoursedata::CL_TYPE;
1.16 raeburn 57: my $lockedtype=&Apache::loncoursedata::CL_LOCKEDTYPE;
1.44 ! raeburn 58: my $credidx=&Apache::loncoursedata::CL_CREDITS;
1.1 raeburn 59: my @localstudents = ();
1.15 raeburn 60: my @futurestudents = ();
61: my @activestudents = ();
1.18 raeburn 62: my @excludedstudents = ();
1.1 raeburn 63: my $currlist;
64: foreach my $uname (keys %{$roster} ) {
65: if ($uname =~ m/^(.+):$dom$/) {
66: if ($$roster{$uname}[$status] eq "Active") {
1.15 raeburn 67: push @activestudents, $1;
68: @{$$currlist{$1}} = @{$$roster{$uname}};
1.1 raeburn 69: push @localstudents, $1;
1.15 raeburn 70: } elsif ( ($$roster{$uname}[$cstart] > time) && ($$roster{$uname}[$cend] > time || $$roster{$uname}[$cend] == 0 || $$roster{$uname}[$cend] eq '') ) {
71: push @futurestudents, $1;
1.1 raeburn 72: @{$$currlist{$1}} = @{$$roster{$uname}};
1.15 raeburn 73: push @localstudents, $1;
1.18 raeburn 74: } elsif ($$roster{$uname}[$lockedtype] == 1) {
75: push @excludedstudents, $1;
1.1 raeburn 76: }
77: }
78: }
79: my $linefeed = '';
80: my $addresult = '';
81: my $dropresult = '';
1.21 raeburn 82: my $switchresult = '';
1.28 raeburn 83: my $photoresult = '';
1.1 raeburn 84: if ($context eq "updatenow") {
85: $linefeed = "</li>\n<li>";
86: } elsif ($context eq "automated") {
87: $linefeed = "\n";
88: }
89: my $enrollcount = 0;
90: my $dropcount = 0;
1.21 raeburn 91: my $switchcount = 0;
1.1 raeburn 92:
1.19 raeburn 93: # Get role names
94: my %longroles = ();
95: open(FILE,"<$$configvars{'lonTabDir'}.'/rolesplain.tab");
96: my @rolesplain = <FILE>;
97: close(FILE);
1.42 raeburn 98: foreach my $item (@rolesplain) {
99: if ($_ =~ /^(st|ta|ex|ad|in|cc|co):([\w\s]+):?([\w\s]*)/) {
100: if ($courseinfo{'type'} eq 'Community') {
101: unless($1 eq 'cc') {
102: $longroles{$1} = $3;
103: }
104: } else {
105: unless($1 eq 'co') {
106: $longroles{$1} = $2;
107: }
108: }
1.19 raeburn 109: }
110: }
111:
1.8 raeburn 112: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand in case initial passwords have to be generated for new users.
113:
1.1 raeburn 114: # Get mapping of IDs to usernames for current LON-CAPA student enrollment for this class
115: my @LCids = ();
116: my %unameFromLCid = ();
117: foreach my $uname (sort keys %{$currlist}) {
118: my $stuID = $$currlist{$uname}[$stuid];
119: if (!grep/^$stuID$/,@LCids) {
120: push @LCids, $stuID;
121: @{$unameFromLCid{$stuID}} = ();
122: }
123: push @{$unameFromLCid{$stuID}},$uname;
124: }
125:
126: # Get latest institutional enrollment for this class.
127: my %allenrolled = ();
128: my @reg_students = ();
1.38 raeburn 129: my %place = &place_hash();
1.1 raeburn 130: my %ucount = ();
131: my %enrollinfo = ();
132: foreach my $class (@{$classesref}) {
133: my %enrolled = ();
134: &parse_classlist($$configvars{'lonDaemons'},$dom,$crs,$class,\%place,$$groupref{$class},\%enrolled);
135: foreach my $uname (sort keys %enrolled ) {
136: if (!grep/^$uname$/,@reg_students) {
137: push @reg_students,$uname;
138: $ucount{$uname} = 0;
139: @{$allenrolled{$uname}} = ();
140: }
141: @{$allenrolled{$uname}[$ucount{$uname}]} = @{$enrolled{$uname}};
142: $ucount{$uname} ++;
143: }
144: }
145:
146: # Check for multiple sections for a single student
147: my @okusers = ();
148: foreach my $uname (@reg_students) {
1.18 raeburn 149: if (grep/^$uname$/,@excludedstudents) {
1.33 raeburn 150: $$logmsg .= &mt('No re-enrollment for [_1] - user was previously manually unenrolled and locked.',$uname).$linefeed;
1.18 raeburn 151: } elsif (@{$allenrolled{$uname}} > 1) {
1.1 raeburn 152: my @sections = ();
153: my $saved;
154: for (my $i=0; $i<@{$allenrolled{$uname}}; $i++) {
155: my @stuinfo = @{$allenrolled{$uname}[$i]};
156: my $secnum = $stuinfo[ $place{'groupID'} ];
157: unless ($secnum eq '') {
158: unless (grep/^$secnum$/,@sections) {
159: $saved = $i;
160: push @sections,$secnum;
161: }
162: }
163: }
164: if (@sections == 0) {
165: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
166: push @okusers, $uname;
167: }
168: elsif (@sections == 1) {
169: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[$saved]};
170: push @okusers, $uname;
171: }
172: elsif (@sections > 1) {
1.33 raeburn 173: $$logmsg .= &mt('[_1] appears in classlists for more than one section of this course, i.e. in sections: ',$uname);
1.1 raeburn 174: foreach (@sections) {
1.5 raeburn 175: $$logmsg .= " $_,";
1.1 raeburn 176: }
1.5 raeburn 177: chop($$logmsg);
1.33 raeburn 178: $$logmsg .= '. '.&mt('Because of this ambiguity, no enrollment action was taken for this student.').$linefeed;
1.1 raeburn 179: }
180: } else {
181: @{$enrollinfo{$uname}} = @{$allenrolled{$uname}[0]};
182: push @okusers, $uname;
183: }
184: }
1.40 weissno 185: # Get mapping of student/employee IDs to usernames for users in institutional data for this class
1.1 raeburn 186: my @allINids = ();
1.3 raeburn 187: my %unameFromINid = ();
1.1 raeburn 188: foreach my $uname (@okusers) {
189: $enrollinfo{$uname}[ $place{'studentID'} ] =~ tr/A-Z/a-z/;
190: my $stuID = $enrollinfo{$uname}[ $place{'studentID'} ];
191: if (grep/^$stuID$/,@allINids) {
192: push @{$unameFromINid{$stuID}},$uname;
193: } else {
194: push @allINids, $stuID;
195: @{$unameFromINid{$stuID}} = $uname;
196: }
197: }
1.28 raeburn 198:
1.5 raeburn 199: # Explicitly allow access to creation/modification of students if called as an automated process.
200: if ($context eq 'automated') {
1.22 albertel 201: $env{'allowed.cst'}='F';
1.5 raeburn 202: }
203:
1.1 raeburn 204: # Compare IDs with existing LON-CAPA enrollment for this class
205: foreach my $uname (@okusers) {
1.5 raeburn 206: unless ($uname eq '') {
207: my %uidhash=&Apache::lonnet::idrget($dom,$uname);
208: my @stuinfo = @{$enrollinfo{$uname}};
1.44 ! raeburn 209: my ($access,$added,$inststatus);
! 210: my $credits;
! 211: if ($showcredits) {
! 212: $credits = $stuinfo[$place{'credits'}];
! 213: $credits =~ s/[^\d\.]//g;
! 214: if ($credits eq $defaultcredits) {
! 215: undef($credits);
! 216: }
! 217: }
! 218: $inststatus = $stuinfo[$place{inststatus}];
1.5 raeburn 219: if (grep/^$uname$/,@localstudents) {
1.1 raeburn 220: # Check for studentID changes
1.5 raeburn 221: if ( ($uidhash{$uname}) && ($uidhash{$uname} !~ /error\:/) ) {
222: unless ( ($uidhash{$uname}) eq ($stuinfo[ $place{studentID} ]) ) {
1.33 raeburn 223: $$logmsg .= &mt('Change in ID for [_1]. StudentID in LON-CAPA system is [_2]; StudentID in institutional data is [_3].',$uname,$uidhash{$uname},$stuinfo[ $place{studentID} ]).$linefeed;
1.5 raeburn 224: }
1.1 raeburn 225: }
1.16 raeburn 226: # Check for switch from manual to auto
227: unless (($$currlist{$uname}[$type] eq "auto") || ($$currlist{$uname}[$lockedtype] eq "1") || (!$adds) ) {
228: # drop manually added student
1.38 raeburn 229: my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto','',$cid,'',$context);
1.16 raeburn 230: # re-enroll as auto student
231: if ($drop_reply !~ /^ok/) {
1.33 raeburn 232: $$logmsg .= &mt('An error occured during the attempt to convert [_1] from a manual type to an auto type student - [_2].',$uname,$drop_reply).$linefeed;
1.16 raeburn 233: } else {
234: # re-enroll as auto student
235: my ($auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,$emailaddr,$pid,$emailenc);
236: &prepare_add($authtype,$autharg,$enddate,$startdate,\@stuinfo,\%place,\$dom,\$uname,\$auth,\$authparam,\$first,\$middle,\$last,\$gene,\$usec,\$end,\$start,\$emailaddr,\$pid,\$emailenc);
237: if ($$currlist{$uname}[$sec] ne $usec) {
1.33 raeburn 238: my $showoldsec = $$currlist{$uname}[$sec];
239: if ($$currlist{$uname}[$sec] eq '') {
240: $showoldsec = &mt('none');
241: }
242: my $showsec = $usec;
243: if ($usec eq '') {
244: $showsec = &mt('none');
245: }
1.44 ! raeburn 246: $switchresult .= &mt('Section for [_1] switched from [_2] to [_3].',$uname,$showoldsec,$showsec).$linefeed;
1.21 raeburn 247: if ($context eq 'automated') {
1.44 ! raeburn 248: $$logmsg .= &mt('Section switch for [_1] from [_2] to [_3].',$uname,$showoldsec,$usec).$linefeed;
1.21 raeburn 249: }
250: $switchcount ++;
1.16 raeburn 251: }
1.44 ! raeburn 252: &execute_add($context,'switchtype',$uname,$dom,$auth,
! 253: $authparam,$first,$middle,$last,$gene,
! 254: $pid,$usec,$end,$start,$emailenc,
! 255: $credits,$cid,\$addresult,\$enrollcount,
! 256: $linefeed,$logmsg);
! 257: $added = 1;
1.16 raeburn 258: }
1.44 ! raeburn 259: }
1.1 raeburn 260: # Check for section changes
1.15 raeburn 261: if ($$currlist{$uname}[$sec] eq $stuinfo[ $place{groupID} ]) {
262: # Check for access date changes for students with access starting in the future.
263: if ( (grep/^$uname$/,@futurestudents) && ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
1.16 raeburn 264: my $datechange = &datechange_check($$currlist{$uname}[$cstart],$$currlist{$uname}[$cend],$startdate,$enddate);
1.15 raeburn 265: if ($datechange) {
1.44 ! raeburn 266: my $modify_access_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid,'',$context,$credits);
1.15 raeburn 267: $access = &showaccess($enddate,$startdate);
268: if ($modify_access_result =~ /^ok/) {
1.33 raeburn 269: $$logmsg .= &mt('Change in access dates for [_1].',$uname).$access.$linefeed;
1.44 ! raeburn 270: $added = 1;
1.15 raeburn 271: } else {
1.33 raeburn 272: $$logmsg .= &mt('Error when attempting to change start and/or end access dates for [_1] in section: [_2] -error [_3].',$uname,$stuinfo[$place{groupID}],$modify_access_result).$linefeed;
1.15 raeburn 273: }
274: }
275: }
276: } else {
1.5 raeburn 277: if ( ($$currlist{$uname}[$type] eq "auto") && ($adds == 1) ) {
1.10 raeburn 278: # Delete from roles.db for current section
279: my $expiretime = time;
280: my $uurl='/'.$cid;
281: $uurl=~s/\_/\//g;
282: if ($$currlist{$uname}[$sec]) {
283: $uurl.='/'.$$currlist{$uname}[$sec];
284: }
1.38 raeburn 285: my $expire_role_result = &Apache::lonnet::assignrole($dom,$uname,$uurl,'st',$expiretime,'','','',$context);
1.10 raeburn 286: if ($expire_role_result eq 'ok') {
1.15 raeburn 287: my $modify_section_result;
288: if (grep/^$uname$/,@activestudents) {
1.44 ! raeburn 289: $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,'',$context,$credits);
1.15 raeburn 290: } else {
1.44 ! raeburn 291: $modify_section_result = &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid,'',$context,$credits);
1.15 raeburn 292: $access = &showaccess($enddate,$startdate);
293: }
1.10 raeburn 294: if ($modify_section_result =~ /^ok/) {
1.44 ! raeburn 295: $switchresult .= &mt('Section for [_1] switched from old section: [_2] to new section: [_3].',$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ]).$access.$linefeed;
! 296: $added = 1;
1.21 raeburn 297: if ($context eq 'automated') {
1.44 ! raeburn 298: $$logmsg .= &mt('Section switch for [_1] from [_2] to [_3].',$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ]).$linefeed;
1.21 raeburn 299: }
300: $switchcount ++;
1.10 raeburn 301: } else {
1.33 raeburn 302: $$logmsg .= &mt("Error when attempting section change for [_1], from old section: '[_2]' to new section: '[_3]' -error: [_4]",$uname,$$currlist{$uname}[$sec],$stuinfo[ $place{groupID} ],$modify_section_result).$linefeed;
1.10 raeburn 303: }
1.5 raeburn 304: } else {
1.33 raeburn 305: $$logmsg .= &mt("Error when attempting to expire role for [_1] in old section: '[_2]' -error: '[_3]'.",$uname,$$currlist{$uname}[$sec],$expire_role_result).$linefeed;
1.5 raeburn 306: }
1.1 raeburn 307: }
308: }
1.44 ! raeburn 309: # Check for credits changes
! 310: if (($showcredits) &&
! 311: ($$currlist{$uname}[$credidx] ne $credits) && (!$added)) {
! 312: my $modify_credits_result =
! 313: &Apache::lonnet::modify_student_enrollment($dom,$uname,undef,undef,undef,undef,undef,$stuinfo[ $place{groupID} ],$enddate,$startdate,'auto','',$cid,'',$context,$credits);
! 314: if ($modify_credits_result =~ /^ok/) {
! 315: if ($credits ne '') {
! 316: $$logmsg .= &mt('Credits change for [_1] from [_2] to [_3].',$uname,$$currlist{$uname}[$credidx],$credits).$linefeed;
! 317: } else {
! 318: $$logmsg .= &mt('Credits change for [_1] from [_2] to course default [_3].',$uname,$$currlist{$uname}[$credidx],$defaultcredits).$linefeed;
! 319: }
! 320: } else {
! 321: $$logmsg .= &mt('Error when attempting to change credits for [_1] in section: [_2] -error [_3].',$uname,$stuinfo[$place{groupID}],$modify_credits_result).$linefeed;
! 322: }
! 323: }
1.5 raeburn 324: } else {
1.1 raeburn 325: # Check for changed usernames by checking studentIDs
1.5 raeburn 326: if ( ($stuinfo[ $place{studentID} ] ne '') && (grep/^$stuinfo[ $place{studentID} ]$/,@LCids) ) {
1.27 raeburn 327: foreach my $match ( @{ $unameFromLCid{ $stuinfo[ $place{studentID} ] } } ) {
1.40 weissno 328: $$logmsg .= &mt('A possible change in username has been detected for a student enrolled in this course.').' '.&mt('The existing LON-CAPA classlist contains user: [_1] and student/employee ID: [_2].',$match,$stuinfo[ $place{studentID} ]);
1.27 raeburn 329: if (grep/^$match$/,@okusers) {
1.40 weissno 330: $$logmsg .= &mt('The username [_1] remains in the institutional classlist, but the same student/employee ID is used for new user: [_2] now found in the institutional classlist.',$match,$uname).' '.&mt('You may need to contact your Domain Coordinator to determine how to resolve this issue and whether to move student data files for user: [_1] to [_2].',$match,$uname).' ';
1.27 raeburn 331: } else {
332: unless ($drops == 1) {
1.40 weissno 333: $$logmsg .= &mt('This username - [_1] - has been dropped from the institutional classlist, but the student/employee ID of this user is also used by [_2] who now appears in the institutional classlist.',$match,$uname).' '.&mt('You may need to contact your Domain Coordinator to request a move of the student data files for user: [_1] to [_2].',$match,$uname).' ';
1.5 raeburn 334: }
1.1 raeburn 335: }
1.40 weissno 336: $$logmsg .= &mt('Because of this student/employee ID conflict, the new username - [_1] - has not been added to the LON-CAPA classlist',$uname).$linefeed;
1.1 raeburn 337: }
1.5 raeburn 338: } elsif ($adds == 1) {
1.44 ! raeburn 339: my ($auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,$emailaddr,$pid,$emailenc,$credithours);
1.16 raeburn 340: &prepare_add($authtype,$autharg,$enddate,$startdate,\@stuinfo,\%place,\$dom,\$uname,\$auth,\$authparam,\$first,\$middle,\$last,\$gene,\$usec,\$end,\$start,\$emailaddr,\$pid,\$emailenc);
1.1 raeburn 341: # Check for existing account in this LON-CAPA domain for this username
1.5 raeburn 342: my $uhome=&Apache::lonnet::homeserver($uname,$dom);
343: if ($uhome eq 'no_host') { # User does not exist
1.19 raeburn 344: my $args = {'auth' => $auth,
345: 'authparam' => $authparam,
346: 'emailenc' => $emailenc,
347: 'udom' => $dom,
348: 'uname' => $uname,
349: 'pid' => $pid,
350: 'first' => $first,
351: 'middle' => $middle,
352: 'last' => $last,
353: 'gene' => $gene,
354: 'usec' => $usec,
355: 'end' => $end,
356: 'start' => $start,
357: 'emailaddr' => $emailaddr,
358: 'cid' => $cid,
359: 'crs' => $crs,
360: 'cdom' => $dom,
361: 'context' => $context,
362: 'linefeed' => $linefeed,
1.44 ! raeburn 363: 'inststatus' => $inststatus,
! 364: 'role' => 'st',
1.19 raeburn 365: };
1.44 ! raeburn 366: if ($credits) {
! 367: $args->{'credits'} = $credits;
! 368: }
1.38 raeburn 369: my $outcome = &create_newuser($args,$logmsg,$newusermsg,\$enrollcount,\$addresult,\%longroles,\%courseinfo,$context);
1.5 raeburn 370: } else {
1.44 ! raeburn 371: &execute_add($context,'newstudent',$uname,$dom,$auth,
! 372: $authparam,$first,$middle,$last,$gene,$pid,
! 373: $usec,$end,$start,$emailenc,$credits,
! 374: $cid,\$addresult,\$enrollcount,$linefeed,
! 375: $logmsg);
1.3 raeburn 376: }
1.31 raeburn 377: if ($courseinfo{'showphoto'}) {
1.28 raeburn 378: my ($result,$resulttype) =
379: &Apache::lonnet::auto_checkphotos($uname,$dom,$pid);
380: if ($resulttype) {
381: push(@{$$phototypes{$resulttype}},$uname);
382: }
383: }
1.1 raeburn 384: }
385: }
386: }
387: }
1.31 raeburn 388: if ($courseinfo{'showphoto'}) {
1.28 raeburn 389: if (keys(%{$phototypes})>0) {
390: my %lt = &photo_response_types();
391: foreach my $type (sort(keys(%{$phototypes}))) {
392: my $numphoto = @{$$phototypes{$type}};
393: if ($numphoto > 0) {
394: if ($context eq 'updatenow') {
395: $photoresult .= '<br /><b>'.
1.29 albertel 396: &mt('For [_1] students, photos ',$numphoto).
397: $lt{$type}.'</b><ul><li>';
1.28 raeburn 398: } else {
1.33 raeburn 399: $photoresult .= "\n".&mt("For [quant,_1,student], photos ",$numphoto).
1.29 albertel 400: $lt{$type}."\n";
1.28 raeburn 401: }
402: foreach my $user (@{$$phototypes{$type}}) {
403: $photoresult .= $user.$linefeed;
404: }
405: if ($context eq 'updatenow') {
406: $photoresult = substr($photoresult,0,
1.29 albertel 407: rindex($photoresult,"<li>"));
1.28 raeburn 408: $photoresult .= '</ul><br />';
409: } else {
410: $photoresult .= "\n";
411: }
412: }
413: }
414: }
415: }
416:
1.1 raeburn 417: # Do drops
418: if ( ($drops == 1) && (@reg_students > 0) ) {
419: foreach my $uname (@localstudents) {
420: if ($$currlist{$uname}[$type] eq "auto") {
421: my @saved = ();
422: if (!grep/^$uname$/,@reg_students) {
423: # Check for changed usernames by checking studentIDs
424: if (grep/^$$currlist{$uname}[ $stuid ]$/,@allINids) {
425: foreach my $match (@{$unameFromINid{$$currlist{$uname}[ $stuid ]}} ) {
1.40 weissno 426: $$logmsg .= &mt('A possible change in username has been detected for a student enrolled in this course.').' '.&mt('The existing LON-CAPA classlist contains user: [_1] and student/employee ID: [_2].',$uname,$$currlist{$uname}[ $place{studentID} ]).' '.&mt('This username has been dropped from the institutional classlist, but the same student/employee ID is used for user: [_1] who still appears in the institutional classlist.',$match).' '.&mt('You may need to move the student data files for user: [_1] to [_2]',$uname,$match).' '.&mt('Because of this, user [_1] has not been dropped from the course.',$uname).$linefeed;
1.1 raeburn 427: push @saved,$uname;
428: }
429: } elsif (@saved == 0) {
1.38 raeburn 430: my $drop_reply = &Apache::lonnet::modifystudent($dom,$uname,'','','',undef,undef,undef,undef,$$currlist{$uname}[$sec],time,undef,undef,undef,undef,'auto','',$cid,'',$context);
1.1 raeburn 431: if ($drop_reply !~ /^ok/) {
1.33 raeburn 432: $$logmsg .= &mt('An error occured during the attempt to expire the [_1] from the old section [_2] - [_3].',$uname,$$currlist{$uname}[$sec],$drop_reply).$linefeed;
1.1 raeburn 433: } else {
434: $dropcount ++;
435: my %userenv = &Apache::lonnet::get('environment',['firstname','lastname','id'],$dom,$uname);
1.38 raeburn 436: $dropresult .= $userenv{'firstname'}." ".$userenv{'lastname'}." (".$userenv{'id'}.") - ".$uname.' '.&mt("dropped from section: '[_1]'.",$$currlist{$uname}[$sec]).$linefeed;
1.8 raeburn 437: if ($context eq 'automated') {
1.33 raeburn 438: $$logmsg .= &mt('User [_1] student role expired from course.',$uname).$linefeed;
1.8 raeburn 439: }
1.1 raeburn 440: }
441: }
442: }
443: }
444: }
445: }
1.5 raeburn 446:
447: # Terminated explictly allowed access to student creation/modification
448: if ($context eq 'automated') {
1.22 albertel 449: delete($env{'allowed.cst'});
1.5 raeburn 450: }
1.1 raeburn 451: if ($enrollcount > 0) {
452: if ($context eq "updatenow") {
1.6 raeburn 453: $addresult = substr($addresult,0,rindex($addresult,"<li>"));
1.33 raeburn 454: $addresult = &mt("The following [quant,_1,student was,students were] added to this LON-CAPA course:",$enrollcount).'<br/><ul><li>'.$addresult.'</ul><br/><br/>';
1.1 raeburn 455: } else {
1.33 raeburn 456: $addresult = &mt("The following [quant,_1,student was,students were] added to this LON-CAPA course:",$enrollcount)."\n\n".$addresult."\n\n";
1.21 raeburn 457: }
1.1 raeburn 458: }
459: if ($dropcount > 0) {
460: if ($context eq "updatenow") {
1.6 raeburn 461: $dropresult = substr($dropresult,0,rindex($dropresult,"<li>"));
1.33 raeburn 462: $dropresult = &mt("The following [quant,_1,student was,students were] expired from this LON-CAPA course:",$dropcount).'<br/><ul><li>'.$dropresult.'</ul><br/><br/>';
1.1 raeburn 463: } else {
1.33 raeburn 464: $dropresult = &mt("The following [quant,_1,student was,students were] expired from this LON-CAPA course:",$dropcount)."\n\n".$dropresult."\n\n";
1.1 raeburn 465: }
466: }
1.21 raeburn 467: if ($switchcount > 0) {
468: if ($context eq "updatenow") {
469: $switchresult = substr($switchresult,0,rindex($switchresult,"<li>"));
1.33 raeburn 470: $switchresult = &mt("The following [quant,_1,student] switched sections in this LON-CAPA course:",$switchcount).'<br/><ul><li>'.$switchresult.'</ul><br/><br/>';
1.21 raeburn 471: } else {
1.33 raeburn 472: $switchresult = &mt("The following [quant,_1,student] switched sections in this LON-CAPA course:",$switchcount)."\n\n".$switchresult."\n\n";
1.21 raeburn 473: }
474: }
1.1 raeburn 475: if ( ($adds) && ($enrollcount == 0) ) {
1.33 raeburn 476: $addresult = &mt('There were no new students to add to the course.');
1.1 raeburn 477: if ($context eq "updatenow") {
478: $addresult .="<br/><br/>";
479: } else {
480: $addresult .="\n";
481: }
482: }
483: if ( ($drops) && ($dropcount == 0) ) {
1.33 raeburn 484: $dropresult = &mt('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.');
1.1 raeburn 485: if ($context eq "updatenow") {
486: $dropresult .="<br/>";
487: } else {
488: $dropresult .="\n";
489: }
490: }
1.21 raeburn 491: my $changecount = $enrollcount + $dropcount + $switchcount;
1.28 raeburn 492: return ($changecount,$addresult.$photoresult.$dropresult.$switchresult);
1.6 raeburn 493: }
1.1 raeburn 494:
1.19 raeburn 495: sub create_newuser {
1.36 albertel 496: my ($args,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,
497: $courseinfo,$called_context) = @_;
1.19 raeburn 498: my $auth = $args->{'auth'};
499: my $authparam = $args->{'authparam'};
500: my $emailenc = $args->{'emailenc'};
501: my $udom = $args->{'udom'};
502: my $uname = $args->{'uname'};
503: my $pid = $args->{'pid'};
504: my $first = $args->{'first'};
505: my $middle = $args->{'middle'};
506: my $last = $args->{'last'} ;
507: my $gene = $args->{'gene'};
508: my $usec = $args->{'usec'};
509: my $end = $args->{'end'};
510: my $start = $args->{'start'};
511: my $emailaddr = $args->{'emailaddr'};
512: my $cid = $args->{'cid'};
513: my $crs = $args->{'crs'};
514: my $cdom = $args->{'cdom'};
515: my $context = $args->{'context'};
516: my $linefeed = $args->{'linefeed'};
517: my $role = $args->{'role'};
1.44 ! raeburn 518: my $inststatus = $args->{'inststatus'};
! 519: my $credits = $args->{'credits'};
1.19 raeburn 520: my $create_passwd = 0;
521: my $authchk = '';
522: my $outcome;
523: unless ($authparam eq '') { $authchk = 'ok'; };
524: # If no account exists and passwords should be generated
525: if ($auth eq "internal") {
526: if ($authparam eq '') {
527: $authparam = &create_password();
528: if ($authparam eq '') {
529: $authchk = '';
530: } else {
531: $create_passwd = 1;
532: $authchk = 'ok';
533: }
534: }
535: } elsif ($auth eq "localauth") {
1.34 raeburn 536: ($authparam,$create_passwd,$authchk) = &Apache::lonnet::auto_create_password($crs,$cdom,$authparam,$udom);
1.19 raeburn 537: } elsif ($auth =~ m/^krb/) {
538: if ($authparam eq '') {
1.33 raeburn 539: $$logmsg .= &mt('No Kerberos domain was provided for the new user - [_1], so the new user was not enrolled in the course',$uname).$linefeed;
1.19 raeburn 540: $authchk = 'invalid';
541: }
542: } else {
543: $authchk = 'invalid';
1.33 raeburn 544: $$logmsg .= &mt('An invalid authentication type was provided for the new user - [_1], so the user was not enrolled in the course.',$uname).$linefeed;
1.34 raeburn 545: }
1.19 raeburn 546: if ($authchk eq 'ok') {
547: # Now create user.
548: my $type = 'auto';
549: my $userurl = '/'.$cdom.'/'.$crs;
550: if ($usec ne '') {
551: $userurl .= '/'.$usec;
552: }
553: if ($context eq 'createowner' || $context eq 'createcourse') {
554: my $result = &Apache::lonnet::modifyuser($udom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,'1',undef,$emailaddr);
555: if ($result eq 'ok' && $context eq 'createcourse') {
1.36 albertel 556: $outcome = &Apache::loncommon::commit_standardrole($udom,$uname,$userurl,$role,$start,$end,$cdom,$crs,$usec,$called_context);
1.19 raeburn 557: unless ($outcome =~ /^Error:/) {
558: $outcome = 'ok';
559: }
560: } else {
561: $outcome = $result;
562: }
563: } else {
1.44 ! raeburn 564: $outcome=&Apache::lonnet::modifystudent($udom,$uname,$pid,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,'',undef,$emailaddr,'auto','',$cid,'',$called_context,$inststatus,$credits);
1.19 raeburn 565: }
566: if ($outcome eq 'ok') {
567: my $access = &showaccess($end,$start);
1.33 raeburn 568: my $showsec = $usec;
569: if ($usec eq '') {
570: $showsec = &mt('none');
571: }
1.38 raeburn 572: $$addresult .= "$first $last ($pid) - $uname ".&mt("enrolled in section: '[_1]'.",$showsec).$access.$linefeed;
1.19 raeburn 573: unless ($context eq 'createowner' || $context eq 'createcourse') {
574: $$enrollcount ++;
575: }
1.36 albertel 576: if ($called_context eq 'automated') {
1.33 raeburn 577: $$logmsg .= &mt('New [_1] user [_2] added successfully.',$udom,$uname);
1.19 raeburn 578: }
579: unless ($emailenc eq '' || $context eq 'createowner' || $context eq 'createcourse') {
580: my %emailHash;
581: $emailHash{'critnotification'} = $emailenc;
582: $emailHash{'notification'} = $emailenc;
1.23 raeburn 583: $emailHash{'permanentemail'} = $emailenc;
1.19 raeburn 584: my $putresult = &Apache::lonnet::put('environment',\%emailHash,$udom,$uname);
585: }
586: if ($create_passwd) {
587: # Send e-mail with initial password to new user at $emailaddr.
588: # If e-mail address is invalid, send password via message to courseowner i
589: # (if automated call) or to user if roster update.
590: if ($emailaddr eq '') {
1.33 raeburn 591: $$newusermsg .= &mt(' username: [_1], password: [_2]',$uname,$authparam).$linefeed."\n";
1.19 raeburn 592: } else {
1.33 raeburn 593: my $subject = &mt('New LON-CAPA account');
1.19 raeburn 594: my $body;
1.41 raeburn 595: my $portalurl = 'http://'.$ENV{'SERVER_NAME'};
596: my $protocol = 'http';
597: my $lonhost=&Apache::lonnet::domain($udom,'primary');
598: if ($lonhost ne '') {
599: my $ip = &Apache::lonnet::get_host_ip($lonhost);
600: if ($Apache::lonnet::protocol{$lonhost} eq 'https') {
601: $protocol = 'https';
602: }
603: if ($ip ne '') {
604: $portalurl = $protocol.'://'.$ip
605: }
606: }
1.19 raeburn 607: if ($context eq 'createowner') {
1.41 raeburn 608: $body = &mt('A user account has been created for you while creating your new course in the LON-CAPA course management and online homework system.')."\n\n".&mt('You should log-in to the system using the following credentials:')."\n".&mt('username: ').$uname."\n".&mt('password: ').$authparam."\n\n".&mt('The URL you should use to access the LON-CAPA system at your institution is: ').$portalurl."\n\n";
1.19 raeburn 609: } elsif ($context eq 'createcourse') {
1.41 raeburn 610: $body = &mt('You have been assigned the role of [_1] in a new course: [_2] - [_3] in the LON-CAPA course management and online homework system.',$$longroles{$role},$$courseinfo{'description'},$$courseinfo{'inst_code'}).' '.&mt('As you did not have an existing user account in the system, one has been created for you.')."\n\n".&mt("You should log-in to the system using the following credentials:\nusername: [_1]\npassword: [_2]",$uname,$authparam)."\n\n".&mt('The URL you should use to access the LON-CAPA system at your institution is: ').$portalurl."\n\n";
1.19 raeburn 611: } else {
612: my $access_start = 'immediately';
613: if ($start > 0) {
614: $access_start = localtime($start)
615: }
1.41 raeburn 616: $body = &mt('You have been enrolled in the LON-CAPA system at your institution, because you are a registered student in a class which is using the LON-CAPA couse management and online homework system.')."\n\n".&mt("You should log-in to the system using the following credentials:\nusername: [_1]\npassword: [_2]",$uname,$authparam)."\n\n".&mt('The URL you should use to access the LON-CAPA system at your institution is: ').$portalurl."\n\n".&mt('When you log-in you will be able to access the LON-CAPA course for [_1] - [_2] starting [_3].',$$courseinfo{'description'},$$courseinfo{'inst_code'},$access_start)."\n";
1.19 raeburn 617: }
618: &Apache::lonmsg::sendemail($emailaddr,$subject,$body);
619: }
1.36 albertel 620: if ($called_context eq 'automated') {
1.33 raeburn 621: $$logmsg .= &mt(' Initial password - sent to ').$emailaddr.$linefeed;
1.19 raeburn 622: }
623: } else {
1.36 albertel 624: if ($called_context eq 'automated') {
1.19 raeburn 625: $$logmsg .= $linefeed;
626: }
627: }
628: } else {
1.33 raeburn 629: $$logmsg .= &mt('An error occurred adding new user [_1] - [_2].',$uname,$outcome).$linefeed;
1.19 raeburn 630: }
1.34 raeburn 631: } else {
632: $$logmsg .= &mt('An error occurred adding the new user [_1] because the authcheck failed for authtype [_2] and parameter [_3].',$uname,$auth,$authparam).' '.&mt('The authcheck response was [_1].',$authchk).$linefeed;
1.19 raeburn 633: }
634: return $outcome;
635: }
636:
1.16 raeburn 637: sub prepare_add {
638: my ($authtype,$autharg,$enddate,$startdate,$stuinfo,$place,$dom,$uname,$auth,$authparam,$first,$middle,$last,$gene,$usec,$end,$start,$emailaddr,$pid,$emailenc) = @_;
639: $$auth = $$stuinfo[ $$place{'authtype'} ];
640: $$authparam = $$stuinfo[ $$place{'autharg'} ];
641: $$first = $$stuinfo[ $$place{'firstname'} ];
642: $$middle = $$stuinfo[ $$place{'middlename'} ];
643: $$last = $$stuinfo[ $$place{'lastname'} ];
644: $$gene = $$stuinfo[ $$place{'generation'} ];
645: $$usec = $$stuinfo[ $$place{'groupID'} ];
646: $$end = $$stuinfo[ $$place{'enddate'} ];
647: $$start = $$stuinfo[ $$place{'startdate'} ];
648: $$emailaddr = $$stuinfo[ $$place{'email'} ];
649: $$pid = $$stuinfo[ $$place{'studentID'} ];
650:
651: # remove non alphanumeric values from section
652: $$usec =~ s/\W//g;
653:
654: unless ($$emailaddr =~/^[^\@]+\@[^\@]+$/) { $$emailaddr =''; }
655: $$emailenc = &HTML::Entities::encode($$emailaddr,'<>&"');
656:
657: # Use course defaults where entry is absent
658: if ( ($$auth eq '') || (!defined($$auth)) ) {
659: $$auth = $authtype;
660: }
661: if ( ($$authparam eq '') || (!defined($$authparam)) ) {
662: $$authparam = $autharg;
663: }
664: if ( ($$end eq '') || (!defined($$end)) ) {
665: $$end = $enddate;
666: }
667: if ( ($$start eq '') || (!defined($$start)) ) {
668: $$start = $startdate;
669: }
670: # Clean up whitespace
671: foreach ($dom,$uname,$pid,$first,$middle,$last,$gene,$usec) {
672: $$_ =~ s/(\s+$|^\s+)//g;
673: }
674: return;
675: }
676:
677: sub execute_add {
1.44 ! raeburn 678: my ($context,$caller,$uname,$dom,$auth,$authparam,$first,$middle,$last,
! 679: $gene,$pid,$usec,$end,$start,$emailenc,$credits,$cid,$addresult,
! 680: $enrollcount,$linefeed,$logmsg) = @_;
1.16 raeburn 681: # Get the user's information and authentication
1.44 ! raeburn 682: my %userenv = &Apache::lonnet::get('environment',['firstname','middlename','lastname','generation','id','critnotification','notification','permanentemail','inststatus'],$dom,$uname);
1.16 raeburn 683: my ($tmp) = keys(%userenv);
684: if ($tmp =~ /^(con_lost|error)/i) {
685: %userenv = ();
686: }
687: # Get the user's e-mail address
688: if ($userenv{critnotification} =~ m/%40/) {
689: unless ($emailenc eq $userenv{critnotification}) {
1.41 raeburn 690: $$logmsg .= &mt('Current critical notification e-mail - [_1] for [_2] is different to e-mail address in institutional classlist - [_3].',
691: $userenv{critnotification},$uname,$emailenc).
692: $linefeed;
1.16 raeburn 693: }
694: }
695: if ($userenv{notification} =~ m/%40/) {
1.23 raeburn 696: unless ($emailenc eq $userenv{notification}) {
1.41 raeburn 697: $$logmsg .= &mt('Current standard notification e-mail - [_1] for [_2] is different to e-mail address in institutional classlist - [_3].',
698: $userenv{notification},$uname,$emailenc).
699: $linefeed;
1.16 raeburn 700: }
701: }
1.23 raeburn 702: if ($userenv{permanentemail} =~ m/%40/) {
703: unless ($emailenc eq $userenv{permanentemail}) {
1.33 raeburn 704: $$logmsg .= &mt('Current permanent e-mail
705: - [_1] for [_2] is different to e-mail address in institutional classlist - [_3]',$userenv{permanentemail},$uname,$emailenc).$linefeed;
1.23 raeburn 706: }
707: }
1.16 raeburn 708: my $krbdefdom = '';
709: my $currentauth=&Apache::lonnet::queryauthenticate($uname,$dom);
710: if ($currentauth=~/^(krb[45]):(.*)/) {
711: $currentauth = $1;
712: $krbdefdom = $2;
713: } elsif ($currentauth=~ /^(unix|internal|localauth):/) {
714: $currentauth = $1;
715: } else {
1.33 raeburn 716: $$logmsg .= &mt('Invalid authentication method [_1] for [_2].',$currentauth,$uname).$linefeed;
1.16 raeburn 717: }
718: # Report if authentication methods are different.
719: if ($currentauth ne $auth) {
1.33 raeburn 720: $$logmsg .= &mt("Authentication type mismatch for [_1] - '[_2]' in system, '[_3]' based on information in classlist or default for this course.",$uname,$currentauth,$auth).$linefeed;
1.16 raeburn 721: } elsif ($auth =~ m/^krb/) {
722: if ($krbdefdom ne $authparam) {
1.33 raeburn 723: $$logmsg .= &mt("Kerberos domain mismatch for [_1] - '[_2]' in system, '[_3]' based on information in classlist or default for this course.",$uname,$krbdefdom,$authparam).$linefeed;
1.16 raeburn 724: }
725: }
726:
727: # Check user data
728: if ($first ne $userenv{'firstname'} ||
729: $middle ne $userenv{'middlename'} ||
730: $last ne $userenv{'lastname'} ||
731: $gene ne $userenv{'generation'} ||
1.23 raeburn 732: $pid ne $userenv{'id'} ||
733: $emailenc ne $userenv{'permanentemail'} ) {
1.16 raeburn 734: # Make the change(s)
735: my %changeHash;
736: $changeHash{'firstname'} = $first;
737: $changeHash{'middlename'} = $middle;
738: $changeHash{'lastname'} = $last;
739: $changeHash{'generation'} = $gene;
740: $changeHash{'id'} = $pid;
1.23 raeburn 741: $changeHash{'permanentemail'} = $emailenc;
1.16 raeburn 742: my $putresult = &Apache::lonnet::put('environment',\%changeHash,$dom,$uname);
743: if ($putresult eq 'ok') {
1.37 raeburn 744: $$logmsg .= &mt('User information updated for user: [_1] prior to enrollment.',$uname).$linefeed;
1.16 raeburn 745: } else {
1.33 raeburn 746: $$logmsg .= &mt('There was a problem modifying user data for existing user - [_1] -error: [_2], enrollment will still be attempted.',$uname,$putresult).$linefeed;
1.16 raeburn 747: }
748: }
749:
750: # Assign the role of student in the course.
1.44 ! raeburn 751: my $classlist_reply =
! 752: &Apache::lonnet::modify_student_enrollment($dom,$uname,$pid,$first,$middle,
! 753: $last,$gene,$usec,$end,$start,
! 754: 'auto','',$cid,'',$context,
! 755: $credits);
1.16 raeburn 756: if ($classlist_reply eq 'ok') {
757: my $access = &showaccess($end,$start);
1.33 raeburn 758: my $showsec = $usec;
759: if ($usec eq '') {
760: $showsec = &mt('none');
761: }
1.16 raeburn 762: if ($caller eq 'switchtype') {
1.38 raeburn 763: $$logmsg .= &mt("Existing user [_1] detected in institutional classlist - switched from 'manual' to 'auto' enrollment in section [_2].",$uname,$showsec).$access.$linefeed;
1.16 raeburn 764: } elsif ($caller eq 'newstudent') {
765: $$enrollcount ++;
1.38 raeburn 766: $$addresult .= "$first $last ($pid) - $uname ".&mt("enrolled in section '[_1]'.",$showsec).$access.$linefeed;
1.16 raeburn 767: }
768: if ($context eq 'automated') {
1.33 raeburn 769: $$logmsg .= &mt('Existing [_1] user [_2] enrolled successfully.',$dom,$uname).$linefeed;
1.16 raeburn 770: }
771: } else {
1.33 raeburn 772: $$logmsg .= &mt('There was a problem updating the classlist db file for user [_1] to show the new enrollment -error: [_2], so no enrollment occurred for this user.',$uname,$classlist_reply).$linefeed;
1.16 raeburn 773: }
774: return;
775: }
776:
777: sub datechange_check {
778: my ($oldstart,$oldend,$startdate,$enddate) = @_;
779: my $datechange = 0;
780: unless ($oldstart eq $startdate) {
781: $datechange = 1;
782: }
783: if (!$datechange) {
784: if (!$oldend) {
785: if ($enddate) {
786: $datechange = 1;
787: }
788: } elsif ($oldend ne $enddate) {
789: $datechange = 1;
790: }
791: }
792: return $datechange;
793: }
794:
1.15 raeburn 795: sub showaccess {
796: my ($end,$start) = @_;
797: my $showstart;
798: my $showend;
799: if ( (!$start) || ($start <= time) ) {
800: $showstart = 'immediately';
801: } else {
802: $showstart = &Apache::lonlocal::locallocaltime($start);
803: }
804: if (!$end) {
805: $showend = 'no end date';
806: } else {
807: $showend = &Apache::lonlocal::locallocaltime($end);
808: }
1.33 raeburn 809: my $access_msg = ' '.&mt('Access starts: [_1], ends: [_2].',$showstart,$showend);
1.15 raeburn 810: return $access_msg;
811: }
812:
1.1 raeburn 813: sub parse_classlist {
1.6 raeburn 814: my ($tmpdir,$dom,$crs,$class,$placeref,$groupID,$studentsref) = @_;
1.5 raeburn 815: my $xmlfile = $tmpdir."/tmp/".$dom."_".$crs."_".$class."_classlist.xml";
1.6 raeburn 816: my $uname = '';
817: my @state;
1.44 ! raeburn 818: my @items = ('autharg','authtype','email','firstname','generation','lastname','middlename','studentID','credits','inststatus');
1.6 raeburn 819: my $p = HTML::Parser->new
820: (
821: xml_mode => 1,
822: start_h =>
823: [sub {
824: my ($tagname, $attr) = @_;
825: push @state, $tagname;
826: if ("@state" eq "students student") {
827: $uname = $attr->{username};
1.43 raeburn 828: $$studentsref{$uname}[ $$placeref{'groupID'} ] = $groupID;
1.6 raeburn 829: }
830: }, "tagname, attr"],
831: text_h =>
832: [sub {
833: my ($text) = @_;
1.43 raeburn 834: if ("@state" eq "students student startdate") {
1.8 raeburn 835: my $start = $text;
836: unless ($text eq '') {
837: $start = &process_date($text);
838: }
839: $$studentsref{$uname}[ $$placeref{'startdate'} ] = $start;
840: } elsif ("@state" eq "students student enddate") {
841: my $end = $text;
842: unless ($text eq '') {
843: $end = &process_date($text);
844: }
845: $$studentsref{$uname}[ $$placeref{'enddate'} ] = $end;
1.6 raeburn 846: } else {
847: foreach my $item (@items) {
848: if ("@state" eq "students student $item") {
849: $$studentsref{$uname}[ $$placeref{$item} ] = $text;
850: }
851: }
852: }
853: }, "dtext"],
854: end_h =>
855: [sub {
856: my ($tagname) = @_;
857: pop @state;
858: }, "tagname"],
859: );
860:
861: $p->parse_file($xmlfile);
862: $p->eof;
1.8 raeburn 863: if (-e "$xmlfile") {
864: unlink $xmlfile;
865: }
1.3 raeburn 866: return;
1.1 raeburn 867: }
868:
1.8 raeburn 869: sub process_date {
870: my $timestr = shift;
871: my $timestamp = '';
872: if ($timestr =~ m/^\d{4}:\d{2}:\d{2}/) {
873: my @entries = split/:/,$timestr;
874: for (my $j=0; $j<@entries; $j++) {
875: if ( length($entries[$j]) > 1 ) {
876: $entries[$j] =~ s/^0//;
877: }
878: }
879: $entries[1] = $entries[1] - 1;
880: $timestamp = timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]);
881: }
882: return $timestamp;
883: }
884:
1.1 raeburn 885: sub create_password {
1.8 raeburn 886: my $passwd = '';
1.11 raeburn 887: 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");
1.8 raeburn 888: for (my $i=0; $i<8; $i++) {
889: my $lettnum = int (rand 2);
890: my $item = '';
891: if ($lettnum) {
892: $item = $letts[int( rand(26) )];
893: my $uppercase = int(rand 2);
894: if ($uppercase) {
895: $item =~ tr/a-z/A-Z/;
896: }
897: } else {
898: $item = int( rand(10) );
899: }
900: $passwd .= $item;
901: }
902: return ($passwd);
1.9 raeburn 903: }
904:
1.19 raeburn 905: sub get_courseinfo {
906: my ($dom,$crs,$courseinfo) = @_;
907: my $owner;
908: if (defined($dom) && defined($crs)) {
1.44 ! raeburn 909: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.showphoto','description','internal.defaultcredits'],$dom,$crs);
1.19 raeburn 910: if ( defined($settings{'internal.coursecode'}) ) {
911: $$courseinfo{'inst_code'} = $settings{'internal.coursecode'};
912: }
913: if ( defined($settings{'description'}) ) {
914: $$courseinfo{'description'} = $settings{'description'};
915: }
1.31 raeburn 916: if ( defined($settings{'internal.showphoto'}) ) {
917: $$courseinfo{'showphoto'} = $settings{'internal.showphoto'};
1.28 raeburn 918: }
1.44 ! raeburn 919: if ( defined($settings{'internal.credithours'}) ) {
! 920: $$courseinfo{'defaultcredits'} = $settings{'internal.defaultcredits'};
! 921: }
1.19 raeburn 922: }
923: return;
924: }
925:
1.38 raeburn 926: sub place_hash {
927: my %place = (
928: autharg => 0,
929: authtype => 1,
930: email => 2,
931: enddate => 3,
932: firstname => 4,
933: generation => 5,
934: groupID => 6,
935: lastname => 7,
936: middlename => 8,
937: startdate => 9,
938: studentID => 10,
1.44 ! raeburn 939: credits => 11,
! 940: inststatus => 12,
1.38 raeburn 941: );
942: return %place;
943: }
1.1 raeburn 944:
1.28 raeburn 945: sub photo_response_types {
1.29 albertel 946: my %lt = &Apache::lonlocal::texthash(
1.28 raeburn 947: 'same' => 'remained unchanged',
948: 'update' => 'were updated',
949: 'new' => 'were added',
950: 'missing' => 'were missing',
951: 'error' => 'were not imported because an error occurred',
952: 'nouser' => 'were for users without accounts',
1.40 weissno 953: 'noid' => 'were for users without student/employee IDs',
1.29 albertel 954: );
1.28 raeburn 955: return %lt;
956: }
957:
958:
1.1 raeburn 959: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>