--- loncom/automation/batchcreatecourse.pm 2016/09/01 01:05:05 1.40.2.1 +++ loncom/automation/batchcreatecourse.pm 2020/07/18 13:49:53 1.40.2.1.4.1 @@ -1,5 +1,5 @@ # -# $Id: batchcreatecourse.pm,v 1.40.2.1 2016/09/01 01:05:05 raeburn Exp $ +# $Id: batchcreatecourse.pm,v 1.40.2.1.4.1 2020/07/18 13:49:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -80,6 +80,7 @@ use strict; # msu # shift # 365 +# create # # 1 # 1 @@ -188,12 +189,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 { @@ -211,10 +216,12 @@ sub create_courses { $longroles{'Community'}{$1} = $3; } } - my ($logmsg,$keysmsg,$newusermsg,$addresult,%codehash); + 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) { @@ -226,25 +233,52 @@ 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) { $codehash{$courseid} = $code; } + if ($details{$num}{'coursecode'} ne '') { + 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); + return ($output,$logmsg,$cloneinfo,$keysmsg,\%codehash,\%instcodes); } ############################################################# @@ -267,7 +301,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'); my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID'); @@ -393,6 +427,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 @@ -404,6 +439,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 @@ -411,8 +448,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'}; @@ -500,6 +538,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'}, @@ -517,6 +558,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, @@ -552,17 +594,21 @@ 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; } } else { return; } - + # # Make owner a coordinator #