--- loncom/automation/batchcreatecourse.pm 2014/01/03 18:42:16 1.40 +++ loncom/automation/batchcreatecourse.pm 2020/07/20 01:02:00 1.40.2.3.2.1 @@ -1,5 +1,5 @@ # -# $Id: batchcreatecourse.pm,v 1.40 2014/01/03 18:42:16 raeburn Exp $ +# $Id: batchcreatecourse.pm,v 1.40.2.3.2.1 2020/07/20 01:02:00 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -80,14 +80,17 @@ use strict; # msu # shift # 365 +# create # # 1 # 1 +# 1 # 0 # keyadmin:msu # 1 # 1 # +# # 1 # 1 # @@ -152,7 +155,7 @@ use strict; # # Many of these are binary options (corresponding to either checkboxes or # radio buttons in the interactive CCRS page). Examples include: -# setpolicy, setcontent, setkeys, disableresdis, disablechat, openall, +# setpolicy, setcontent, setcomment, setkeys, disableresdis, disablechat, openall, # uniquecode # # A value of 1 between opening and closing tags is equivalent to a @@ -187,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 { @@ -210,10 +217,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) { @@ -225,25 +234,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); } ############################################################# @@ -266,9 +302,9 @@ 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','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 @dateitems = ('enrollstart','enrollend','accessstart','accessend','openallfrom'); my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID'); my $p = HTML::Parser->new ( @@ -392,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 @@ -403,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 @@ -410,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'}; @@ -499,6 +539,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'}, @@ -516,6 +559,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, @@ -534,12 +578,14 @@ sub build_course { endaccess => $details->{'accessend'}, setpolicy => $details->{'setpolicy'}, setcontent => $details->{'setcontent'}, + setcomment => $details->{'setcomment'}, reshome => $reshome, setkeys => $details->{'setkeys'}, keyauth => $details->{'keyauth'}, disresdis => $details->{'disresdis'}, disablechat => $details->{'disablechat'}, openall => $details->{'openall'}, + openallfrom => $details->{'openallfrom'}, firstres => $firstres }; if ($details->{'textbook'}) { @@ -550,10 +596,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; }