--- loncom/automation/batchcreatecourse.pm 2006/08/11 19:30:52 1.17
+++ loncom/automation/batchcreatecourse.pm 2009/08/08 19:55:15 1.28
@@ -1,5 +1,5 @@
#
-# $Id: batchcreatecourse.pm,v 1.17 2006/08/11 19:30:52 albertel Exp $
+# $Id: batchcreatecourse.pm,v 1.28 2009/08/08 19:55:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,9 +31,8 @@ use HTML::Parser;
use Time::Local;
use Apache::lonnet;
use Apache::loncommon;
-use Apache::loncreatecourse;
-use Apache::loncreateuser;
use Apache::lonlocal;
+use LONCAPA qw(:match);
use strict;
@@ -77,11 +76,13 @@ use strict;
# 20
# 466011437c34194msul1
# msu
+# shift
+# 365
#
# 1
# 1
# 0
-# keyadmin@msu
+# keyadmin:msu
# 1
# 1
#
@@ -220,7 +221,9 @@ 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);
- $$courseids{$courseid} = $details{$num}{'class'};
+ if ($courseid =~m{^/$match_domain/$match_courseid}) {
+ $$courseids{$courseid} = $details{$num}{'class'};
+ }
}
}
}
@@ -248,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
@@ -367,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
@@ -376,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
@@ -385,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;
@@ -445,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'},
@@ -464,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,
@@ -490,14 +504,16 @@ sub build_course {
openall => $$details{$num}{'openall'},
firstres => $firstres
};
-
- my %host_servers = &Apache::loncommon::get_library_servers($cdom);
+ 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::loncreatecourse::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;
}
@@ -506,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);
}
#
@@ -542,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)) {
@@ -555,7 +571,7 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncreateuser::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) {
@@ -569,14 +585,14 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncreateuser::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::loncreateuser::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);
}
}
}
@@ -592,7 +608,7 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncreateuser::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'}}) {
@@ -600,12 +616,12 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- my $stdresult = &Apache::loncreateuser::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::loncreateuser::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);
}
}
}