--- loncom/automation/batchcreatecourse.pm 2020/07/18 13:49:53 1.40.2.1.4.1 +++ loncom/automation/batchcreatecourse.pm 2019/07/26 02:28:28 1.43 @@ -1,5 +1,5 @@ # -# $Id: batchcreatecourse.pm,v 1.40.2.1.4.1 2020/07/18 13:49:53 raeburn Exp $ +# $Id: batchcreatecourse.pm,v 1.43 2019/07/26 02:28:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -80,7 +80,6 @@ use strict; # msu # shift # 365 -# create # # 1 # 1 @@ -165,7 +164,7 @@ use strict; # firstres can be nav, syl, or blank for "Navigate Contents", Syllabus, or # no entry respectively. # -# crstype can be Course or Community +# crstype can be Course, Community or Placement # # crsquota is the total disk space permitted for course group portfolio files # in all course groups. @@ -189,16 +188,12 @@ use strict; # uname - username of DC who is requesting course creation # udom - domain of DC who is requesting course creation # -# 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. +# 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. ############################################################# sub create_courses { @@ -216,12 +211,10 @@ sub create_courses { $longroles{'Community'}{$1} = $3; } } - my ($logmsg,$cloneinfo,$keysmsg,$newusermsg,$addresult,$user_lh, - %codehash,%instcodes); + my ($logmsg,$keysmsg,$newusermsg,$addresult,%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) { @@ -233,16 +226,14 @@ 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, - $clonemsg,\$newusermsg,\$addresult,\%enrollcount, - \$output,\$keysmsg,undef,undef,undef,undef,\$code); + my $courseid = + &build_course($dom,$num,$context,$reqdetails,\%longroles,\$logmsg,\$newusermsg, + \$addresult,\%enrollcount,\$output,\$keysmsg,undef,undef,undef,undef,\$code); if ($courseid =~m{^/$match_domain/$match_courseid}) { $$courseids{$courseid} = $details{$num}{'class'}; if ($code) { @@ -252,33 +243,11 @@ 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,$cloneinfo,$keysmsg,\%codehash,\%instcodes); + return ($output,$logmsg,$keysmsg,\%codehash,\%instcodes); } ############################################################# @@ -301,7 +270,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','tinyurls','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','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'); @@ -427,7 +396,6 @@ 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 @@ -439,8 +407,6 @@ 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 @@ -448,9 +414,8 @@ sub parse_coursereqs { ######################################################### sub build_course { - my ($cdom,$num,$context,$details,$longroles,$logmsg,$clonemsg,$newusermsg, - $addresult,$enrollcount,$output,$keysmsg,$udom,$uname,$cnum,$category, - $coderef,$callercontext,$user_lh) = @_; + my ($cdom,$num,$context,$details,$longroles,$logmsg,$newusermsg,$addresult, + $enrollcount,$output,$keysmsg,$udom,$uname,$cnum,$category,$coderef) = @_; return unless (ref($details) eq 'HASH'); my $owner_uname = $details->{'owner'}; my $owner_domain = $details->{'domain'}; @@ -467,7 +432,11 @@ sub build_course { $rolenames = $longroles->{'Community'}; } } else { - $crstype = 'Course'; + if ($details->{'crstype'} eq 'Placement') { + $crstype = $details->{'crstype'}; + } else { + $crstype = 'Course'; + } $ccrole = 'cc'; if (ref($longroles) eq 'HASH') { $rolenames = $longroles->{'Course'}; @@ -490,6 +459,8 @@ sub build_course { if ($firstres eq '') { if ($crstype eq 'Community') { $firstres = 'nav'; + } elsif ($crstype eq 'Placement') { + $firstres = 'blank'; } else { $firstres = 'syl'; } @@ -538,9 +509,6 @@ 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'}, @@ -558,7 +526,6 @@ sub build_course { clonedomain => $details->{'clonedom'}, datemode => $details->{'datemode'}, dateshift => $details->{'dateshift'}, - tinyurls => $details->{'tinyurls'}, crsid => $details->{'optional_id'}, curruser => $details->{'owner'}, crssections => $sectionstr, @@ -594,14 +561,10 @@ sub build_course { $$logmsg .= &mt('Invalid home server for course').': '.$details->{'coursehome'}; return; } - my ($success,$msg,$cloneinfo) = + my ($success, $msg) = &Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum, - $udom,$uname,$context,$cnum,$category,$coderef, - $callercontext,$user_lh); + $udom,$uname,$context,$cnum,$category,$coderef); $$logmsg .= $msg; - if ((ref($clonemsg) eq 'ARRAY') && (ref($cloneinfo) eq 'ARRAY')) { - push(@{$clonemsg},@{$cloneinfo}); - } if (!$success) { return; }