--- loncom/automation/batchcreatecourse.pm 2006/08/11 19:30:52 1.17
+++ loncom/automation/batchcreatecourse.pm 2008/07/02 18:44:16 1.27
@@ -1,5 +1,5 @@
#
-# $Id: batchcreatecourse.pm,v 1.17 2006/08/11 19:30:52 albertel Exp $
+# $Id: batchcreatecourse.pm,v 1.27 2008/07/02 18:44:16 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
@@ -445,12 +448,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 +471,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 +499,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);
+ $$logmsg .= $msg;
+ if (!$success) {
+ return;
+ }
} else {
return;
}
@@ -506,7 +517,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 +553,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 +566,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 +580,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 +603,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 +611,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);
}
}
}