--- loncom/automation/batchcreatecourse.pm 2007/05/11 01:48:26 1.21
+++ loncom/automation/batchcreatecourse.pm 2009/08/08 19:55:15 1.28
@@ -1,5 +1,5 @@
#
-# $Id: batchcreatecourse.pm,v 1.21 2007/05/11 01:48:26 raeburn Exp $
+# $Id: batchcreatecourse.pm,v 1.28 2009/08/08 19:55:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -76,6 +76,8 @@ use strict;
# 20
# 466011437c34194msul1
# msu
+# shift
+# 365
#
# 1
# 1
@@ -219,7 +221,7 @@ sub create_courses {
&parse_coursereqs($newcoursedir.'/'.$request, \%details);
foreach my $num (sort keys %details) {
my $courseid = &build_course($dom,$num,$context,\%details,\%longroles,\$logmsg,\$newusermsg,\$addresult,\%enrollcount,\$output,\$keysmsg);
- if ($courseid =~ /^$match_courseid$/) {
+ if ($courseid =~m{^/$match_domain/$match_courseid}) {
$$courseids{$courseid} = $details{$num}{'class'};
}
}
@@ -249,7 +251,7 @@ sub parse_coursereqs {
my $xlist = 0;
my $userkey = '';
my $role = '';
- 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','crstype','crsquota');
+ my @items = ('title','optional_id','coursecode','coursehome','reshome','nonstandard','adds','drops','topmap','firstres','clonecrs','clonedom','datemode','dateshift','showphotos','setpolicy','setcontent','setkeys','keyauth','disresdis','disablechat','openall','notify_owner','notify_dc','crstype','crsquota');
my @dateitems = ('enrollstart','enrollend','accessstart','accessend');
my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID');
my $p = HTML::Parser->new
@@ -368,7 +370,7 @@ sub parse_coursereqs {
# build_course()
#
# inputs
-# domain
+# course domain
# course request number
# context - auto if called from command line, web if called from DC web interface
# ref to hash of course creation information
@@ -377,8 +379,13 @@ sub parse_coursereqs {
# ref to scalar used to accumulate messages sent to new users
# ref to scalar used to accumulate results of new user additions
# ref to hash of enrollment counts for different roles
-# ref to scalar used to accumulate iformation about added roles
-# ref to scalar used to accumulate
+# ref to scalar used to accumulate information about added roles
+# ref to scalar used to accumulate
+# ref to scalar used to accumulate information about access keys
+# domain of DC creating course
+# username of DC creating course
+# optional course number, if unique course number already obtained (e.g., for
+# course requests submitted via course request form.
#
# outputs
# LON-CAPA courseID for new (created) course
@@ -386,7 +393,7 @@ sub parse_coursereqs {
#########################################################
sub build_course {
- my ($cdom,$num,$context,$details,$longroles,$logmsg,$newusermsg,$addresult,$enrollcount,$output,$keysmsg,$udom,$uname) = @_;
+ my ($cdom,$num,$context,$details,$longroles,$logmsg,$newusermsg,$addresult,$enrollcount,$output,$keysmsg,$udom,$uname,$cnum) = @_;
my $owner_uname = $$details{$num}{'owner'};
my $owner_domain = $$details{$num}{'domain'};
my $owner = $owner_uname.':'.$owner_domain;
@@ -446,12 +453,16 @@ sub build_course {
'linefeed' => $linefeed,
'role' => 'cc',
};
- $outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo);
+ $outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo,$context);
} else {
$outcome = 'ok';
}
if ($outcome eq 'ok') {
+ if ($$details{$num}{'datemode'} !~ /^(preserve|shift|delete)$/) {
+ $$details{$num}{'datemode'} = 'shift';
+ $$details{$num}{'dateshift'} = 365;
+ }
my $courseargs = {
ccuname => $$details{$num}{'owner'},
ccdomain => $$details{$num}{'domain'},
@@ -465,6 +476,8 @@ sub build_course {
crsquota => $$details{$num}{'crsquota'},
clonecourse => $$details{$num}{'clonecrs'},
clonedomain => $$details{$num}{'clonedom'},
+ datemode => $$details{$num}{'datemode'},
+ dateshift => $$details{$num}{'dateshift'},
crsid => $$details{$num}{'optional_id'},
curruser => $$details{$num}{'owner'},
crssections => $sectionstr,
@@ -491,14 +504,16 @@ sub build_course {
openall => $$details{$num}{'openall'},
firstres => $firstres
};
-
my %host_servers = &Apache::lonnet::get_servers($cdom,'library');
if (! exists($host_servers{$$details{$num}{'coursehome'}})) {
$$logmsg .= &mt('Invalid home server for course').': '.$$details{$num}{'coursehome'};
return;
}
-
- &Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum,$udom,$uname);
+ my ($success, $msg) = &Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum,$udom,$uname,$context,$cnum);
+ $$logmsg .= $msg;
+ if (!$success) {
+ return;
+ }
} else {
return;
}
@@ -507,7 +522,7 @@ sub build_course {
# Make owner a course coordinator
#
if (($owner_domain) && ($owner_uname)) {
- &Apache::lonnet::assignrole($owner_domain,$owner_uname,$courseid,'cc');
+ &Apache::lonnet::assignrole($owner_domain,$owner_uname,$courseid,'cc','','','','',$context);
}
#
@@ -543,7 +558,7 @@ sub build_course {
'linefeed' => $linefeed,
'role' => $$details{$num}{'users'}{$userkey}{'roles'}[0],
};
- $outcome = &LONCAPA::Enrollment::create_newuser($userargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo);
+ $outcome = &LONCAPA::Enrollment::create_newuser($userargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo,$context);
# now add other roles and other sections.
if ($outcome eq 'ok') {
if (($firstrole ne 'st') && (@{$$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) {
@@ -556,7 +571,7 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
+ $$output .= &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
}
}
if (@{$$details{$num}{'users'}{$userkey}{'roles'}} > 1) {
@@ -570,14 +585,14 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
+ $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
} else {
foreach my $usec (@{$$details{$num}{'users'}{$userkey}{$curr_role}{'usec'}}) {
$url = '/'.$crsudom.'/'.$crsunum;
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
+ $$output .= &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
}
}
}
@@ -593,7 +608,7 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
+ $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
} else {
if (@{$$details{$num}{'users'}{$userkey}{$curr_role}{'usec'}} > 0) {
foreach my $usec (@{$$details{$num}{'users'}{$userkey}{$curr_role}{'usec'}}) {
@@ -601,12 +616,12 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- my $stdresult = &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec);
+ my $stdresult = &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
$$output .= $stdresult;
}
} else {
$url = '/'.$crsudom.'/'.$crsunum;
- $$output .= &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,'');
+ $$output .= &Apache::loncommon::commit_standardrole($userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,'',$context);
}
}
}