--- loncom/automation/batchcreatecourse.pm 2013/03/01 04:49:15 1.38 +++ loncom/automation/batchcreatecourse.pm 2013/12/25 09:52:47 1.39 @@ -1,5 +1,5 @@ # -# $Id: batchcreatecourse.pm,v 1.38 2013/03/01 04:49:15 raeburn Exp $ +# $Id: batchcreatecourse.pm,v 1.39 2013/12/25 09:52:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -75,6 +75,7 @@ use strict; # # nav # 20 +# 1 # 466011437c34194msul1 # msu # shift @@ -151,7 +152,8 @@ 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, setkeys, disableresdis, disablechat, openall, +# uniquecode # # A value of 1 between opening and closing tags is equivalent to a # checked checkbox or 'Yes' response in the original CCRS web page. @@ -178,16 +180,19 @@ use strict; # /home/httpd/perl/tmp/addcourse/$dom/auto/pending if $context = auto # /home/httpd/perl/tmp/addcourse/$dom/web/$uname_$udom/pending if $context = web # -# inputs (five) - requests - ref to array of filename(s) containing course requests +# inputs (six) - requests - ref to array of filename(s) containing course requests # courseids - ref to hash to store LON-CAPA course ids of new courses # context - auto if called from command line, web if called from browser # dom - domain for which the course is being created # uname - username of DC who is requesting course creation # udom - domain of DC who is requesting course creation # -# outputs (three) - output - text recording user roles added etc. -# logmsg - text to be logged -# keysmsg - text containing link(s) to manage keys page(s) +# 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 { @@ -205,7 +210,7 @@ sub create_courses { $longroles{'Community'}{$1} = $3; } } - my ($logmsg,$keysmsg,$newusermsg,$addresult); + my ($logmsg,$keysmsg,$newusermsg,$addresult,%codehash); my %enrollcount = (); my $newcoursedir = LONCAPA::tempdir().'/addcourse/'.$dom.'/'.$context; if ($context eq 'auto') { @@ -224,15 +229,21 @@ sub create_courses { &parse_coursereqs($newcoursedir.'/'.$request, \%details); foreach my $num (sort(keys(%details))) { my $reqdetails = $details{$num}; - my $courseid = &build_course($dom,$num,$context,$reqdetails,\%longroles,\$logmsg,\$newusermsg,\$addresult,\%enrollcount,\$output,\$keysmsg); + my $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) { + $codehash{$courseid} = $code; + } } } } } } - return ($output,$logmsg,$keysmsg); + return ($output,$logmsg,$keysmsg,\%codehash); } ############################################################# @@ -255,7 +266,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','setkeys','keyauth','disresdis','disablechat','openall','notify_owner','notify_dc','crstype','crsquota'); + 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 @possroles = qw(st ad ep ta in cc co); my @dateitems = ('enrollstart','enrollend','accessstart','accessend'); my @useritems = ('autharg','authtype','firstname','generation','lastname','middlename','studentID'); @@ -385,12 +396,13 @@ sub parse_coursereqs { # ref to scalar used to accumulate results of new user additions # ref to hash of enrollment counts for different roles # ref to scalar used to accumulate information about added roles -# ref to scalar used to accumulate # ref to scalar used to accumulate information about access keys # domain of DC creating course # username of DC creating course # optional course number, if unique course number already obtained (e.g., for -# course requests submitted via course request form. +# course requests submitted via course request form. +# optional category +# optional ref to scalar for six character unique identifier # # outputs # LON-CAPA courseID for new (created) course @@ -398,7 +410,8 @@ sub parse_coursereqs { ######################################################### sub build_course { - my ($cdom,$num,$context,$details,$longroles,$logmsg,$newusermsg,$addresult,$enrollcount,$output,$keysmsg,$udom,$uname,$cnum,$category) = @_; + 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'}; @@ -498,6 +511,7 @@ sub build_course { crscode => $details->{'coursecode'}, defaultcredits => $details->{'defaultcredits'}, crsquota => $details->{'crsquota'}, + uniquecode => $details->{'uniquecode'}, clonecourse => $details->{'clonecrs'}, clonedomain => $details->{'clonedom'}, datemode => $details->{'datemode'}, @@ -533,7 +547,9 @@ sub build_course { $$logmsg .= &mt('Invalid home server for course').': '.$details->{'coursehome'}; return; } - my ($success, $msg) = &Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum,$udom,$uname,$context,$cnum,$category); + my ($success, $msg) = + &Apache::loncommon::construct_course($courseargs,$logmsg,\$courseid,\$crsudom,\$crsunum, + $udom,$uname,$context,$cnum,$category,$coderef); $$logmsg .= $msg; if (!$success) { return;