--- loncom/automation/batchcreatecourse.pm 2020/05/22 15:05:36 1.44
+++ loncom/automation/batchcreatecourse.pm 2020/07/01 20:09:03 1.45
@@ -1,5 +1,5 @@
#
-# $Id: batchcreatecourse.pm,v 1.44 2020/05/22 15:05:36 raeburn Exp $
+# $Id: batchcreatecourse.pm,v 1.45 2020/07/01 20:09:03 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -80,6 +80,7 @@ use strict;
# msu
# shift
# 365
+# create
#
# 1
# 1
@@ -189,12 +190,16 @@ use strict;
# uname - username of DC who is requesting course creation
# udom - domain of DC who is requesting course creation
#
-# outputs (four) - output - text recording user roles added etc.
-# logmsg - text to be logged
-# keysmsg - text containing link(s) to manage keys page(s)
-# codehash - reference to hash containing courseID => unique code
-# where unique code is a 6 character code, to distribute
-# to students as a shortcut to the course.
+# outputs (six) - output - text recording user roles added etc.
+# logmsg - text to be logged
+# cloneinfo - text output from cloning
+# keysmsg - text containing link(s) to manage keys page(s)
+# codehash - reference to hash containing courseID => unique code
+# where unique code is a 6 character code, to distribute
+# to students as a shortcut to the course.
+# instcodes - references to hash of an array, where keys are
+# institutional codes and values are an array of
+# courseIDs of courses with that code.
#############################################################
sub create_courses {
@@ -212,10 +217,12 @@ sub create_courses {
$longroles{'Community'}{$1} = $3;
}
}
- my ($logmsg,$keysmsg,$newusermsg,$addresult,%codehash,%instcodes);
+ my ($logmsg,$cloneinfo,$keysmsg,$newusermsg,$addresult,$user_lh,
+ %codehash,%instcodes);
my %enrollcount = ();
my $newcoursedir = LONCAPA::tempdir().'/addcourse/'.$dom.'/'.$context;
if ($context eq 'auto') {
+ $user_lh = &Apache::loncommon::user_lang($uname,$udom);
$newcoursedir .= '/pending';
} else {
if ($uname && $udom) {
@@ -227,14 +234,16 @@ sub create_courses {
if (@{$requests} > 0) {
foreach my $request (@{$requests}) {
my %details = ();
+ my $clonemsg = [];
if (-e $newcoursedir.'/'.$request) {
&parse_coursereqs($newcoursedir.'/'.$request, \%details);
foreach my $num (sort(keys(%details))) {
my $reqdetails = $details{$num};
my $code;
- my $courseid =
- &build_course($dom,$num,$context,$reqdetails,\%longroles,\$logmsg,\$newusermsg,
- \$addresult,\%enrollcount,\$output,\$keysmsg,undef,undef,undef,undef,\$code);
+ my $courseid =
+ &build_course($dom,$num,$context,$reqdetails,\%longroles,\$logmsg,
+ $clonemsg,\$newusermsg,\$addresult,\%enrollcount,
+ \$output,\$keysmsg,undef,undef,undef,undef,\$code);
if ($courseid =~m{^/$match_domain/$match_courseid}) {
$$courseids{$courseid} = $details{$num}{'class'};
if ($code) {
@@ -244,11 +253,33 @@ sub create_courses {
push(@{$instcodes{$details{$num}{'coursecode'}}},$courseid);
}
}
+ if (@{$clonemsg}) {
+ if ($context eq 'web') {
+ $cloneinfo .= '
';
+ }
+ foreach my $item (@{$clonemsg}) {
+ if (ref($item) eq 'HASH') {
+ if ($context eq 'auto') {
+ $cloneinfo .= &mt_user($user_lh,$item->{mt},
+ @{$item->{args}});
+ } else {
+ $cloneinfo .= &mt($item->{mt},@{$item->{args}});
+ }
+ }
+ if ($context eq 'web') {
+ $cloneinfo .= '
';
+ }
+ $cloneinfo .= "\n";
+ }
+ if ($context eq 'web') {
+ $cloneinfo .= '
';
+ }
+ }
}
}
}
}
- return ($output,$logmsg,$keysmsg,\%codehash,\%instcodes);
+ return ($output,$logmsg,$cloneinfo,$keysmsg,\%codehash,\%instcodes);
}
#############################################################
@@ -271,7 +302,7 @@ sub parse_coursereqs {
my $xlist = 0;
my $userkey = '';
my $role = '';
- my @items = ('title','optional_id','coursecode','defaultcredits','coursehome','reshome','nonstandard','adds','drops','topmap','firstres','clonecrs','clonedom','datemode','dateshift','showphotos','setpolicy','setcontent','setcomment','setkeys','keyauth','disresdis','disablechat','openall','notify_owner','notify_dc','crstype','crsquota','uniquecode');
+ my @items = ('title','optional_id','coursecode','defaultcredits','coursehome','reshome','nonstandard','adds','drops','topmap','firstres','clonecrs','clonedom','datemode','dateshift','tinyurls','showphotos','setpolicy','setcontent','setcomment','setkeys','keyauth','disresdis','disablechat','openall','notify_owner','notify_dc','crstype','crsquota','uniquecode');
my @possroles = qw(st ad ep ta in cc co);
my @dateitems = ('enrollstart','enrollend','accessstart','accessend','openallfrom');
my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID');
@@ -397,6 +428,7 @@ sub parse_coursereqs {
# ref to hash of course creation information
# ref to hash of role descriptions
# ref to scalar used to accumulate log messages
+# ref to array used to accumulate messages about cloning
# 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
@@ -408,6 +440,8 @@ sub parse_coursereqs {
# course requests submitted via course request form.
# optional category
# optional ref to scalar for six character unique identifier
+# caller context (e.g., auto)
+# user language handle, if caller context is 'auto'
#
# outputs
# LON-CAPA courseID for new (created) course
@@ -415,8 +449,9 @@ sub parse_coursereqs {
#########################################################
sub build_course {
- my ($cdom,$num,$context,$details,$longroles,$logmsg,$newusermsg,$addresult,
- $enrollcount,$output,$keysmsg,$udom,$uname,$cnum,$category,$coderef) = @_;
+ my ($cdom,$num,$context,$details,$longroles,$logmsg,$clonemsg,$newusermsg,
+ $addresult,$enrollcount,$output,$keysmsg,$udom,$uname,$cnum,$category,
+ $coderef,$callercontext,$user_lh) = @_;
return unless (ref($details) eq 'HASH');
my $owner_uname = $details->{'owner'};
my $owner_domain = $details->{'domain'};
@@ -510,6 +545,9 @@ sub build_course {
$details->{'datemode'} = 'shift';
$details->{'dateshift'} = 365;
}
+ if ($details->{'tinyurls'} !~ /^(delete|transfer|create)$/) {
+ $details->{'tinyurls'} = 'create';
+ }
my $courseargs = {
ccuname => $details->{'owner'},
ccdomain => $details->{'domain'},
@@ -527,6 +565,7 @@ sub build_course {
clonedomain => $details->{'clonedom'},
datemode => $details->{'datemode'},
dateshift => $details->{'dateshift'},
+ tinyurls => $details->{'tinyurls'},
crsid => $details->{'optional_id'},
curruser => $details->{'owner'},
crssections => $sectionstr,
@@ -563,10 +602,14 @@ sub build_course {
$$logmsg .= &mt('Invalid home server for course').': '.$details->{'coursehome'};
return;
}
- my ($success, $msg) =
+ my ($success,$msg,$cloneinfo) =
&Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum,
- $udom,$uname,$context,$cnum,$category,$coderef);
+ $udom,$uname,$context,$cnum,$category,$coderef,
+ $callercontext,$user_lh);
$$logmsg .= $msg;
+ if ((ref($clonemsg) eq 'ARRAY') && (ref($cloneinfo) eq 'ARRAY')) {
+ push(@{$clonemsg},@{$cloneinfo});
+ }
if (!$success) {
return;
}