Annotation of loncom/automation/batchcreatecourse.pm, revision 1.1
1.1 ! raeburn 1: package LONCAPA::batchcreatecourse;
! 2: use LONCAPA::Configuration;
! 3: use LONCAPA::Enrollment;
! 4: use HTML::Parser;
! 5: use Time::Local;
! 6: use Apache::Constants;
! 7: use Apache::lonnet;
! 8: use Apache::loncreatecourse;
! 9: use Apache::lonlocal;
! 10:
! 11: # Collection of routines used for batch creation of courses and users.
! 12: # &create_courses() should be called by an Autocreate.pl
! 13: # script via a cron entry, or alternatively from a web page, after upload
! 14: # of a file containing an XML description of a course request (lonbatchccrs.pm).
! 15: #
! 16: # XML file(s) describing courses that are to be created in domain $dom are stored in
! 17: # /home/httpd/perl/tmp/addcourse/$dom. Each XML file is deleted after it has been
! 18: # parsed.
! 19: #
! 20: # &create_courses() will create an account for the course owner
! 21: # (if one does not currently exist), will create the course (cloning if necessary),
! 22: # and will add additional instructional staff (creating accounts if necessary).
! 23: #
! 24: # Example of XML file (which could contain more than one class to be created):
! 25: #
! 26: #<?xml version="1.0" encoding="UTF-8"?>
! 27: #<!DOCTYPE text>
! 28: #<class id="ss05ubw101">
! 29: # <title>Underwater Basket Weaving</title>
! 30: # <coursecode>ss05ubw101</coursecode>
! 31: # <coursehome>msul1</coursehome>
! 32: # <coursedomain>msu</coursedomain>
! 33: # <reshome>/res/msu/</reshome>
! 34: # <optional_id></optional_id>
! 35: # <adds>1</adds>
! 36: # <drops>1</drops>
! 37: # <enrollstart>2005:01:04:10:30</enrollstart>
! 38: # <enrollend>2005:07:04:20:30</enrollend>
! 39: # <accessstart>2005:01:10:10:30</accessstart>
! 40: # <accessend>2005:05:31:10:30</accessend>
! 41: # <authentication>
! 42: # <method>krb4</method>
! 43: # <param>MSU.EDU</param>
! 44: # </authentication>
! 45: # <nonstandard></nonstandard>
! 46: # <topmap></topmap>
! 47: # <firstres>nav</firstres>
! 48: # <clonecrs>466011437c34194msul1</clonecrs>
! 49: # <clonedom>msu</clonedom>
! 50: # <showphotos></showphotos>
! 51: # <setpolicy>1</setpolicy>
! 52: # <setcontent>1</setcontent>
! 53: # <setkeys>0</setkeys>
! 54: # <keyauth>keyadmin@msu</keyauth>
! 55: # <disresdis>1</disresdis>
! 56: # <disablechat>1</disablechat>
! 57: # <openall></openall>
! 58: # <notify_dc>1</notify_dc>
! 59: # <notify_owner>1</notify_owner>
! 60: # <owner>
! 61: # <username>sparty</username>
! 62: # <domain>msu</domain>
! 63: # <authtype>krb4</authtype>
! 64: # <autharg>MSU.EDU</autharg>
! 65: # </owner>
! 66: # <sections>
! 67: # <section>
! 68: # <inst>001</inst>
! 69: # <loncapa>1</loncapa>
! 70: # </section>
! 71: # <section>
! 72: # <inst>002</inst>
! 73: # <loncapa>2</loncapa>
! 74: # </section>
! 75: # </sections>
! 76: # <crosslists>
! 77: # <xlist>
! 78: # <inst>ss05zzz101001</inst>
! 79: # <loncapa>1</loncapa>
! 80: # </xlist>
! 81: # </crosslists>
! 82: # <users>
! 83: # <user>
! 84: # <username>sparty</username>
! 85: # <domain>msu</domain>
! 86: # <email>sparty@msu.edu</email>
! 87: # <authtype>krb4</authtype>
! 88: # <autharg></autharg>
! 89: # <firstname>MSU</firstname>
! 90: # <generation></generation>
! 91: # <lastname>Spartan</lastname>x
! 92: # <middlename></middlename>
! 93: # <studentID></studentID>
! 94: # <roles></roles>
! 95: # </user>
! 96: # <user>
! 97: # <username>itds0001</username>
! 98: # <domain>northwood5</domain>
! 99: # <email>itds0001@msu.edu</email>
! 100: # <authtype>int</authtype>
! 101: # <autharg></autharg>
! 102: # <firstname>Info</firstname>
! 103: # <generation></generation>
! 104: # <lastname>Techc</lastname>x
! 105: # <middlename></middlename>
! 106: # <studentID></studentID>
! 107: # <roles>
! 108: # <role id='in'>
! 109: # <start>2005:01:01:12:10</start>
! 110: # <end>2005:12:01:12:10</end>
! 111: # <usec>1</usec>
! 112: # <usec>2</usec>
! 113: # </role>
! 114: # </roles>
! 115: # </user>
! 116: # </users>
! 117: #</class>
! 118: #
! 119: # Many of these are binary options (corresponding to either checkboxes or
! 120: # radio buttons in the interactive CCRS page). Examples include:
! 121: # setpolicy, setcontent, setkeys, disableresdis, disablechat, openall
! 122: #
! 123: # A value of 1 between opening and closing tags is equivalent to a
! 124: # checked checkbox or 'Yes' response in the original CCRS web page.
! 125: # A value of 0 or blank is equivalent to an unchecked box or 'No'
! 126: # response. Dates are in format YYYY:MM:DD:HH:MM:SS (:separators required)
! 127: #
! 128: # firstres can be nav, syl , or blank for "Navigate Contents", Syllabus, or
! 129: # no entry respectively.
! 130: # For format of other parameters, refer to the interactive CCRS page
! 131: # and view how the equivalent parameter is displayed in the web form.
! 132: #
! 133: ##############################################################
! 134: # create_courses() - creates courses described in @$requests,
! 135: # files listed in @$requests are deleted
! 136: # after the files have been parsed.
! 137: #
! 138: # Directory searched for files listed in @$requests
! 139: # is /home/httpd/perl/tmp/addcourse/$dom/auto if $context is auto
! 140: # and /home/httpd/perl/tmp/addcourse/$dom/web/$uname if $context is web
! 141: #
! 142: # inputs (five) - requests - ref to array of filename(s) containing course requests
! 143: # courseids - ref to hash to store LON-CAPA course ids of new courses
! 144: # context - auto if called from command line, web if called from browser
! 145: # dom - domain for which the course is being created
! 146: # uname - username of DC who is requesting course creation from browser
! 147: #
! 148: # outputs (three) - output - text recording user roles added etc.
! 149: # logmsg - text to be logged
! 150: # keysmsg - text containing link(s) to manage keys page(s)
! 151: #############################################################
! 152:
! 153: sub create_courses {
! 154: my ($requests,$courseids,$context,$dom,$uname) = @_;
! 155: my $output;
! 156: my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
! 157: # Get role names
! 158: my %longroles = ();
! 159: open(FILE,"<$perlvarref{'lonTabDir'}.'/rolesplain.tab");
! 160: my @rolesplain = <FILE>;
! 161: close(FILE);
! 162: foreach (@rolesplain) {
! 163: if ($_ =~ /^(st|ta|ex|ad|in|cc):([\w\s]+)$/) {
! 164: $longroles{$1} = $2;
! 165: }
! 166: }
! 167: my ($logmsg,$keysmsg,$newusermsg,$addresult);
! 168: my %enrollcount = ();
! 169: my $newcoursedir = $$perlvarref{'lonDaemons'}.'/tmp/addcourse/'.$dom.'/'.$context;
! 170: if ($uname) {
! 171: unless ($context eq 'auto') {
! 172: $newcoursedir .= '/'.$uname;
! 173: }
! 174: }
! 175: if (@{$requests} > 0) {
! 176: foreach my $request (@{$requests}) {
! 177: my %details = ();
! 178: if (-e $newcoursedir.'/'.$request) {
! 179: &parse_coursereqs($newcoursedir.'/'.$request, \%details);
! 180: foreach my $num (sort keys %details) {
! 181: my $courseid = &build_course($dom,$num,$context,\%details,\%longroles,\$logmsg,\$newusermsg,\$addresult,\%enrollcount,\$output,\$keysmsg);
! 182: $$courseids{$courseid} = $enrollcount;
! 183: }
! 184: }
! 185: }
! 186: }
! 187: return ($output,$logmsg,$keysmsg);
! 188: }
! 189:
! 190: #############################################################
! 191: #
! 192: # parse_coursereqs()
! 193: # inputs (two) - coursefile - path to XML file containing course(s) to be created.
! 194: # - details - reference to hash containing extracted information.
! 195: # outputs (none)
! 196: #
! 197: ############################################################
! 198:
! 199: sub parse_coursereqs {
! 200: my ($coursefile,$details) = @_;
! 201: # Note all start and end dates should be in this format:
! 202: # YYYY:MM:DD:HH:MM:SS (:separators required).
! 203: my $uname = '';
! 204: my @state = ();
! 205: my $num = 0;
! 206: my $secid = 0;
! 207: my $xlist = 0;
! 208: my $userkey = '';
! 209: my $role = '';
! 210: my @items = ('title','optional_id','coursecode','coursehome','reshome','nonstandard','adds','drops','topmap','firstres','clonecrs','clonedom','showphotos','setpolicy','setcontent','setkeys','keyauth','disresdis','disablechat','openall','notify_owner','notify_dc');
! 211: my @dateitems = ('enrollstart','enrollend','accessstart','accessend');
! 212: my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID');
! 213: my $p = HTML::Parser->new
! 214: (
! 215: xml_mode => 1,
! 216: start_h =>
! 217: [sub {
! 218: my ($tagname, $attr) = @_;
! 219: push(@state, $tagname);
! 220: if ("@state" eq "class") {
! 221: %{$$details{$num}} = ();
! 222: $$details{$num}{'class'} = $attr->{id};
! 223: %{$$details{$num}{'users'}} = ();
! 224: %{$$details{$num}{'sections'}} = ();
! 225: $secid = 0;
! 226: $xlist = 0;
! 227: }
! 228: if ("@state" eq "class users user roles role") {
! 229: $role = $attr->{id};
! 230: if ($role =~ /^(st|ad|ep|ta|in|cc)$/) {
! 231: push(@{$$details{$num}{'users'}{$userkey}{'roles'}}, $role);
! 232: %{$$details{$num}{'users'}{$userkey}{$role}} = ();
! 233: @{$$details{$num}{'users'}{$userkey}{$role}{'usec'}} = ();
! 234: }
! 235: }
! 236: if ("@state" eq "class sections section") {
! 237: $secid ++;
! 238: %{$$details{$num}{'sections'}{$secid}} = ();
! 239: }
! 240: if ("@state" eq "class crosslists xlist") {
! 241: $xlist ++;
! 242: %{$$details{$num}{'crosslists'}{$xlist}} = ();
! 243: }
! 244: }, "tagname, attr"],
! 245: text_h =>
! 246: [sub {
! 247: my ($text) = @_;
! 248: if ("@state" eq "class owner username") {
! 249: $$details{$num}{'owner'} = $text;
! 250: } elsif ("@state" eq "class owner domain") {
! 251: $$details{$num}{'domain'} = $text;
! 252: } elsif ("@state" eq "class sections section inst") {
! 253: $$details{$num}{'sections'}{$secid}{'inst'} = $text;
! 254: } elsif ("@state" eq "class sections section loncapa") {
! 255: $$details{$num}{'sections'}{$secid}{'loncapa'} = $text;
! 256: } elsif ("@state" eq "class crosslists xlist inst") {
! 257: $$details{$num}{'crosslists'}{$xlist}{'inst'} = $text;
! 258: } elsif ("@state" eq "class crosslists xlist loncapa") {
! 259: $$details{$num}{'crosslists'}{$xlist}{'loncapa'} = $text;
! 260: } elsif ("@state" eq "class owner authtype") {
! 261: $$details{$num}{'ownerauthtype'} = $text;
! 262: } elsif ("@state" eq "class owner autharg") {
! 263: $$details{$num}{'ownerautharg'} = $text;
! 264: } elsif ("@state" eq "class authentication method") {
! 265: $$details{$num}{'authtype'} = $text;
! 266: } elsif ("@state" eq "class authentication param") {
! 267: $$details{$num}{'authparam'} = $text;
! 268: } elsif ("@state" eq "class users user username") {
! 269: $userkey = $text;
! 270: } elsif ("@state" eq "class users user domain") {
! 271: $userkey .= ':'.$text;
! 272: %{$$details{$num}{'users'}{$userkey}} = ();
! 273: @{$$details{$num}{'users'}{$userkey}{'roles'}} = ();
! 274: } elsif ("@state" eq "class users user email") {
! 275: $$details{$num}{'users'}{$userkey}{'emailaddr'} = $text;
! 276: $$details{$num}{'users'}{$userkey}{'emailenc'} = &Apache::lonnet::escape($text);
! 277: } elsif ("@state" eq "class users user roles role start") {
! 278: if ($role =~ /^(st|ad|ep|ta|in|cc)$/) {
! 279: $$details{$num}{'users'}{$userkey}{$role}{'start'} = &process_date($text);
! 280: }
! 281: } elsif ("@state" eq "class users user roles role end") {
! 282: if ($role =~ /^(st|ad|ep|ta|in|cc)$/) {
! 283: $$details{$num}{'users'}{$userkey}{$role}{'end'} = &process_date($text);
! 284: }
! 285: } elsif ("@state" eq "class users user roles role usec") {
! 286: if ($role =~ /^(st|ad|ep|ta|in|cc)$/) {
! 287: unless ($text eq '') {
! 288: push(@{$$details{$num}{'users'}{$userkey}{$role}{'usec'}},$text);
! 289: }
! 290: }
! 291: } else {
! 292: foreach my $item (@items) {
! 293: if ("@state" eq "class $item") {
! 294: $$details{$num}{$item} = $text;
! 295: }
! 296: }
! 297: foreach my $item (@dateitems) {
! 298: if ("@state" eq "class $item") {
! 299: $$details{$num}{$item} = &process_date($text);
! 300: }
! 301: }
! 302: foreach my $item (@useritems) {
! 303: if ("@state" eq "class users user $item") {
! 304: $$details{$num}{'users'}{$userkey}{$item} = $text;
! 305: }
! 306: }
! 307: }
! 308: }, "dtext"],
! 309: end_h =>
! 310: [sub {
! 311: my ($tagname) = @_;
! 312: if ("@state" eq "class") {
! 313: $num ++;
! 314: }
! 315: pop @state;
! 316: }, "tagname"],
! 317: );
! 318:
! 319: $p->parse_file($coursefile);
! 320: $p->eof;
! 321: if (-e "$coursefile") {
! 322: # unlink $coursefile;
! 323: }
! 324: return;
! 325: }
! 326:
! 327: #########################################################
! 328: #
! 329: # build_course()
! 330: #
! 331: # inputs
! 332: # domain
! 333: # course request number
! 334: # context - auto if called from command line, web if called from DC web interface
! 335: # ref to hash of course creation information
! 336: # ref to hash of role descriptions
! 337: # ref to scalar used to accumulate log messages
! 338: # ref to scalar used to accumulate messages sent to new users
! 339: # ref to scalar used to accumulate results of new user additions
! 340: # ref to hash of enrollment counts for different roles
! 341: # ref to scalar used to accumulate iformation about added roles
! 342: # ref to scalar used to accumulate
! 343: #
! 344: # outputs
! 345: # LON-CAPA courseID for new (created) course
! 346: #
! 347: #########################################################
! 348:
! 349: sub build_course {
! 350: my ($cdom,$num,$context,$details,$longoles,$logmsg,$newusermsg,$addresult,$enrollcount,$output,$keysmsg) = @_;
! 351: my $owner_uname = $$details{$num}{'owner'};
! 352: my $owner_domain = $$details{$num}{'domain'};
! 353: my $owner = $owner_uname.':'.$owner_domain;
! 354: my $sectionstr = '';
! 355: my $xliststr = '';
! 356: my $noenddate = '';
! 357: my $outcome;
! 358: my ($courseid,$crsudom,$crsunum);
! 359: my $linefeed;
! 360: if ($context eq 'auto') {
! 361: $linefeed = "\n";
! 362: } else {
! 363: $linefeed = "<br />\n";
! 364: }
! 365: if ($$details{$num}{'accessend'} eq '') {
! 366: $noenddate = 1;
! 367: }
! 368: my $reshome = $$details{$num}{'reshome'};
! 369: if ($reshome eq '') {
! 370: $reshome = '/res/'.$cdom;
! 371: }
! 372: my $firstres = $$details{$num}{'firstres'};
! 373: if ($firstres eq '') {
! 374: $firstres = 'syl';
! 375: }
! 376: foreach my $secid (sort keys %{$$details{$num}{'sections'}}) {
! 377: $sectionstr .= $$details{$num}{'sections'}{$secid}{'inst'}.':'.$$details{$num}{'sections'}{$secid}{'loncapa'};
! 378: }
! 379:
! 380: foreach my $xlist (sort keys %{$$details{$num}{'crosslists'}}) {
! 381: $xliststr .= $$details{$num}{'crosslists'}{$xlist}{'inst'}.':'.$$details{$num}{'crosslists'}{$xlist}{'loncapa'};
! 382: }
! 383:
! 384: my %courseinfo = (
! 385: inst_code => $$details{$num}{'coursecode'},
! 386: description => $$details{$num}{'title'}
! 387: );
! 388: if (&Apache::lonnet::homeserver($$details{$num}{'owner'},$$details{$num}{'domain'}) eq 'no_host') { # Add user if no account
! 389: my $ownerargs = ('auth' => $$details{$num}{'ownerauthtype'},
! 390: 'authparam' => $$details{$num}{'ownerauthparam'},
! 391: 'emailenc' => $$details{$num}{'emailenc'},
! 392: 'dom' => $$details{$num}{'domain'},
! 393: 'uname' => $$details{$num}{'owner'},
! 394: 'pid' => '',
! 395: 'first' => $$details{$num}{'users'}{$owner}{'first'},
! 396: 'middle' => $$details{$num}{'users'}{$owner}{'middle'},
! 397: 'last' => $$details{$num}{'users'}{$owner}{'last'},
! 398: 'gene' => $$details{$num}{'users'}{$owner}{'gene'},
! 399: 'usec' => '',
! 400: 'end' => '',
! 401: 'start' => '',
! 402: 'emailaddr' => $$details{$num}{'users'}{$owner}{'email'},
! 403: 'cid' => '',
! 404: 'context' => 'createowner',
! 405: 'linefeed' => $linefeed,
! 406: 'role' => 'cc'
! 407: );
! 408: $outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,$courseinfo);
! 409: } else {
! 410: $outcome = 'ok';
! 411: }
! 412:
! 413: my $courseargs = {
! 414: ccuname => $$details{$num}{'owner'},
! 415: ccdomain => $$details{$num}{'domain'},
! 416: cdescr => $$details{$num}{'title'},
! 417: curl => $$details{$num}{'topmap'},
! 418: course_domain => $cdom,
! 419: course_home => $$details{$num}{'coursehome'},
! 420: nonstandard => $$details{$num}{'nonstandard'},
! 421: crscode => $$details{$num}{'coursecode'},
! 422: clonecourse => $$details{$num}{'clonecrs'},
! 423: clonedomain => $$details{$num}{'clonedom'},
! 424: crsid => $$details{$num}{'optional_id'},
! 425: curruser => $$details{$num}{'owner'},
! 426: crssections => $sectionstr,
! 427: crsxlist => $xliststr,
! 428: autoadds => $$details{$num}{'adds'},
! 429: autodrops => $$details{$num}{'drops'},
! 430: notify => $$details{$num}{'notify_owner'},
! 431: notify_dc => $$details{$num}{'notify_dc'},
! 432: no_end_date => $noenddate,
! 433: showphotos => $$details{$num}{'showphotos'},
! 434: authtype => $$details{$num}{'authtype'},
! 435: autharg => $$details{$num}{'authparam'},
! 436: enrollstart => $$details{$num}{'enrollstart'},
! 437: enrollend => $$details{$num}{'enrollend'},
! 438: startaccess => $$details{$num}{'accessstart'},
! 439: endaccess => $$details{$num}{'accessend'},
! 440: setpolicy => $Sdetails{$num}{'setpolicy'},
! 441: setcontent => $$details{$num}{'setcontent'},
! 442: reshome => $reshome,
! 443: setkeys => $$details{$num}{'setkeys'},
! 444: keyauth => $$details{$num}{'keyauth'},
! 445: disresdis => $$details{$num}{'disresdis'},
! 446: disablechat => $$details{$num}{'disablechat'},
! 447: openall => $$details{$num}{'openall'},
! 448: firstres => $firstres
! 449: };
! 450:
! 451: if ($outcome eq 'ok') {
! 452: my %host_servers = &Apache::loncommon::get_library_servers($cdom);
! 453: if (! exists($host_servers{$$details{$num}{'coursehome'}})) {
! 454: $$logmsg .= &mt('Invalid home server for course').': '.$$details{$num}{'coursehome'};
! 455: return;
! 456: }
! 457:
! 458: &Apache::loncreatecourse::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum);
! 459: } else {
! 460: return;
! 461: }
! 462:
! 463: #
! 464: # Make owner a course coordinator
! 465: #
! 466: if (($owner_domain) && ($owner_uname)) {
! 467: &Apache::lonnet::assignrole($owner_domain,$owner_uname,$courseid,'cc');
! 468: }
! 469:
! 470: #
! 471: # Process other reqested users
! 472: #
! 473: my $stulogmsg = '';
! 474: foreach my $userkey (sort keys %{$$details{$num}{'users'}}) {
! 475: my $url = '/'.$crsudom.'/'.$crsunum;
! 476: if (@{$$details{$num}{'users'}{$userkey}{'roles'}} > 0) {
! 477: my ($username,$userdom) = split/:/,$userkey;
! 478: if (&Apache::lonnet::homeserver($username,$userdom) eq 'no_host') { # Add user if no account
! 479: my $firstrole = $$details{$num}{'users'}{$userkey}{'roles'}[0];
! 480: my $firssec = $$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}[0];
! 481: my $userargs = ('auth' => $$details{$num}{'users'}{$userkey}{'authtype'},
! 482: 'authparam' => $$details{$num}{'users'}{$userkey}{'authparam'},
! 483: 'emailenc' => $$details{$num}{'users'}{$userkey}{'emailenc'},
! 484: 'dom' => $userdom,
! 485: 'uname' => $username,
! 486: 'pid' => $$details{$num}{'users'}{$userkey}{'studentID'},
! 487: 'first' => $$details{$num}{'users'}{$userkey}{'first'},
! 488: 'middle' => $$details{$num}{'users'}{$userkey}{'middle'},
! 489: 'last' => $$details{$num}{'users'}{$userkey}{'last'},
! 490: 'gene' => $$details{$num}{'users'}{$userkey}{'gene'},
! 491: 'usec' => $firstsec,
! 492: 'end' => $$details{$num}{'users'}{$userkey}{'end'},
! 493: 'start' => $$details{$num}{'users'}{$userkey}{'start'},
! 494: 'emailaddr' => $$details{$num}{'users'}{$userkey}{'email'},
! 495: 'cid' => $courseid,
! 496: 'context' => 'createcourse',
! 497: 'linefeed' => $linefeed,
! 498: 'role' => $$details{$num}{'users'}{$userkey}{'roles'}[0],
! 499: );
! 500: $outcome = &LONCAPA::Enrollment::create_newuser($userargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,$courseinfo);
! 501: # now add other roles and other sections.
! 502: if ($outcome eq 'ok') {
! 503: if (($firstrole ne 'st') && (@{$$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) {
! 504: for (my $i=1; $i<@{$$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}}; $i++) {
! 505: my $curr_role = $firstrole;
! 506: my $start = $$details{$num}{'users'}{$userkey}{$curr_role}{'start'};
! 507: my $end = $$details{$num}{'users'}{$userkey}{$curr_role}{'end'};
! 508: my $usec = $$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}[$i];
! 509: $url = '/'.$crsudom.'/'.$crsunum;
! 510: if ($usec ne '') {
! 511: $url .= '/'.$usec;
! 512: }
! 513: $$output .= &Apache::loncreateuser::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
! 514: }
! 515: }
! 516: if (@{$$details{$num}{'users'}{$userkey}{'roles'}} > 1) {
! 517: for (my $j=1; $j<@{$$details{$num}{'users'}{$userkey}{'roles'}}; $j++) {
! 518: my $curr_role = $$details{$num}{'users'}{$userkey}{'roles'}[$j];
! 519: my $start = $$details{$num}{'users'}{$userkey}{$curr_role}{'start'};
! 520: my $end = $$details{$num}{'users'}{$userkey}{$curr_role}{'end'};
! 521: if ($curr_role eq 'st') {
! 522: my $usec = $$details{$num}{'users'}{$userkey}{$curr_role}{'usec'}[0];
! 523: $url = '/'.$crsudom.'/'.$crsunum;
! 524: if ($usec ne '') {
! 525: $url .= '/'.$usec;
! 526: }
! 527: $$output .= &Apache::loncreateuser::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
! 528: } else {
! 529: foreach my $usec (@{$$details{$num}{'users'}{$userkey}{$curr_role}{'usec'}}) {
! 530: $url = '/'.$crsudom.'/'.$crsunum;
! 531: if ($usec ne '') {
! 532: $url .= '/'.$usec;
! 533: }
! 534: $$output .= &Apache::loncreateuser::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
! 535: }
! 536: }
! 537: }
! 538: }
! 539: }
! 540: } else {
! 541: foreach my $curr_role (@{$$details{$num}{'users'}{$userkey}{'roles'}}) {
! 542: my $start = $$details{$num}{'users'}{$userkey}{$curr_role}{'start'};
! 543: my $end = $$details{$num}{'users'}{$userkey}{$curr_role}{'end'};
! 544: if ($curr_role eq 'st') {
! 545: my $usec = $$details{$num}{'users'}{$userkey}{$curr_role}{'usec'}[0];
! 546: $url = '/'.$crsudom.'/'.$crsunum;
! 547: if ($usec ne '') {
! 548: $url .= '/'.$usec;
! 549: }
! 550: $$output .= &Apache::loncreateuser::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
! 551: } else {
! 552: if (@{$$details{$num}{'users'}{$userkey}{$curr_role}{'usec'}} > 0) {
! 553: foreach my $usec (@{$$details{$num}{'users'}{$userkey}{$curr_role}{'usec'}}) {
! 554: $url = '/'.$crsudom.'/'.$crsunum;
! 555: if ($usec ne '') {
! 556: $url .= '/'.$usec;
! 557: }
! 558: $$output .= &Apache::loncreateuser::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
! 559: $url = '/'.$crsudom.'/'.$crsunum;
! 560: if ($usec ne '') {
! 561: $url .= '/'.$usec;
! 562: }
! 563: }
! 564: } else {
! 565: $$output .= &Apache::loncreateuser::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,'');
! 566: }
! 567: }
! 568: }
! 569: }
! 570: }
! 571: }
! 572:
! 573: # Information about keys.
! 574: if ($$details{$num}{'setkeys'}) {
! 575: $$keysmsg .=
! 576: '<a href="/adm/managekeys?cid='.$crsudom.'_'.$crsunum.'">'.&mt('Manage Access Keys').'</a> for '.$$details{$num}{'title'}.$linefeed;
! 577: }
! 578: # Flush the course logs so reverse user roles immediately updated
! 579: &Apache::lonnet::flushcourselogs();
! 580: return $courseid;
! 581: }
! 582:
! 583: #########################################################
! 584: #
! 585: # process_date()
! 586: #
! 587: # input - date/time string in format YYYY:MM:DD:HH:MM:SS (:separators required).
! 588: # output - corresponding UNIX time (seconds since epoch).
! 589: #
! 590: #########################################################
! 591:
! 592: sub process_date {
! 593: my $timestr = shift;
! 594: my $timestamp = '';
! 595: if ($timestr eq "No end date") {
! 596: $timestamp = '';
! 597: } else {
! 598: my @entries = split/:/,$timestr;
! 599: for (my $j=0; $j<@entries; $j++) {
! 600: if ( length($entries[$j]) > 1 ) {
! 601: $entries[$j] =~ s/^0//;
! 602: }
! 603: }
! 604: $entries[1] = $entries[1] - 1;
! 605: $timestamp = timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]);
! 606: }
! 607: return $timestamp;
! 608: }
! 609:
! 610: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>