--- loncom/automation/batchcreatecourse.pm 2009/09/05 20:20:17 1.31
+++ loncom/automation/batchcreatecourse.pm 2013/03/01 04:49:15 1.38
@@ -1,5 +1,5 @@
#
-# $Id: batchcreatecourse.pm,v 1.31 2009/09/05 20:20:17 raeburn Exp $
+# $Id: batchcreatecourse.pm,v 1.38 2013/03/01 04:49:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -56,6 +56,7 @@ use strict;
#
Underwater Basket Weaving
# Course
# ss05ubw101
+# 3
# msul1
# msu
# /res/msu/
@@ -122,6 +123,7 @@ use strict;
# Spartanx
#
#
+#
#
#
#
@@ -159,7 +161,7 @@ use strict;
# firstres can be nav, syl, or blank for "Navigate Contents", Syllabus, or
# no entry respectively.
#
-# crstype can be Course or Group
+# crstype can be Course or Community
#
# crsquota is the total disk space permitted for course group portfolio files
# in all course groups.
@@ -197,14 +199,15 @@ sub create_courses {
open(FILE,"<$$perlvarref{'lonTabDir'}.'/rolesplain.tab");
my @rolesplain = ;
close(FILE);
- foreach (@rolesplain) {
- if ($_ =~ /^(st|ta|ex|ad|in|cc):([\w\s]+)$/) {
- $longroles{$1} = $2;
+ foreach my $item (@rolesplain) {
+ if ($item =~ /^(st|ta|ep|ad|in|cc|co):([\w\s]+):?([\w\s]*)/) {
+ $longroles{'Course'}{$1} = $2;
+ $longroles{'Community'}{$1} = $3;
}
}
my ($logmsg,$keysmsg,$newusermsg,$addresult);
my %enrollcount = ();
- my $newcoursedir = $$perlvarref{'lonDaemons'}.'/tmp/addcourse/'.$dom.'/'.$context;
+ my $newcoursedir = LONCAPA::tempdir().'/addcourse/'.$dom.'/'.$context;
if ($context eq 'auto') {
$newcoursedir .= '/pending';
} else {
@@ -252,7 +255,8 @@ sub parse_coursereqs {
my $xlist = 0;
my $userkey = '';
my $role = '';
- my @items = ('title','optional_id','coursecode','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');
+ 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');
my $p = HTML::Parser->new
@@ -272,7 +276,7 @@ sub parse_coursereqs {
}
if ("@state" eq "class users user roles role") {
$role = $attr->{id};
- if ($role =~ /^(st|ad|ep|ta|in|cc)$/) {
+ if (grep(/^\Q$role\E$/,@possroles)) {
push(@{$$details{$num}{'users'}{$userkey}{'roles'}}, $role);
%{$$details{$num}{'users'}{$userkey}{$role}} = ();
@{$$details{$num}{'users'}{$userkey}{$role}{'usec'}} = ();
@@ -318,17 +322,17 @@ sub parse_coursereqs {
@{$$details{$num}{'users'}{$userkey}{'roles'}} = ();
} elsif ("@state" eq "class users user email") {
$$details{$num}{'users'}{$userkey}{'emailaddr'} = $text;
- $$details{$num}{'users'}{$userkey}{'emailenc'} = &Apache::lonnet::escape($text);
+ $$details{$num}{'users'}{$userkey}{'emailenc'} = &LONCAPA::escape($text);
} elsif ("@state" eq "class users user roles role start") {
- if ($role =~ /^(st|ad|ep|ta|in|cc)$/) {
+ if (grep(/^\Q$role\E$/,@possroles)) {
$$details{$num}{'users'}{$userkey}{$role}{'start'} = &process_date($text);
}
} elsif ("@state" eq "class users user roles role end") {
- if ($role =~ /^(st|ad|ep|ta|in|cc)$/) {
+ if (grep(/^\Q$role\E$/,@possroles)) {
$$details{$num}{'users'}{$userkey}{$role}{'end'} = &process_date($text);
}
} elsif ("@state" eq "class users user roles role usec") {
- if ($role =~ /^(st|ad|ep|ta|in|cc)$/) {
+ if (grep(/^\Q$role\E$/,@possroles)) {
unless ($text eq '') {
push(@{$$details{$num}{'users'}{$userkey}{$role}{'usec'}},$text);
}
@@ -403,7 +407,20 @@ sub build_course {
my $xliststr = '';
my $noenddate = '';
my $outcome;
- my ($courseid,$crsudom,$crsunum);
+ my ($courseid,$crsudom,$crsunum,$crstype,$ccrole,$rolenames);
+ if ($details->{'crstype'} eq 'Community') {
+ $crstype = $details->{'crstype'};
+ $ccrole ='co';
+ if (ref($longroles) eq 'HASH') {
+ $rolenames = $longroles->{'Community'};
+ }
+ } else {
+ $crstype = 'Course';
+ $ccrole = 'cc';
+ if (ref($longroles) eq 'HASH') {
+ $rolenames = $longroles->{'Course'};
+ }
+ }
my $linefeed;
if ($context eq 'auto') {
$linefeed = "\n";
@@ -419,7 +436,11 @@ sub build_course {
}
my $firstres = $details->{'firstres'};
if ($firstres eq '') {
- $firstres = 'syl';
+ if ($crstype eq 'Community') {
+ $firstres = 'nav';
+ } else {
+ $firstres = 'syl';
+ }
}
foreach my $secid (sort(keys(%{$details->{'sections'}}))) {
$sectionstr .= $details->{'sections'}{$secid}{'inst'}.':'.$details->{'sections'}{$secid}{'loncapa'}.',';
@@ -453,9 +474,9 @@ sub build_course {
'cid' => '',
'context' => 'createowner',
'linefeed' => $linefeed,
- 'role' => 'cc',
+ 'role' => $ccrole,
};
- $outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo,$context);
+ $outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$rolenames,\%courseinfo,$context);
} else {
$outcome = 'ok';
}
@@ -475,6 +496,7 @@ sub build_course {
course_home => $details->{'coursehome'},
nonstandard => $details->{'nonstandard'},
crscode => $details->{'coursecode'},
+ defaultcredits => $details->{'defaultcredits'},
crsquota => $details->{'crsquota'},
clonecourse => $details->{'clonecrs'},
clonedomain => $details->{'clonedom'},
@@ -521,16 +543,18 @@ sub build_course {
}
#
-# Make owner a course coordinator
+# Make owner a coordinator
#
if (($owner_domain) && ($owner_uname)) {
- &Apache::lonnet::assignrole($owner_domain,$owner_uname,$courseid,'cc','','','','',$context);
+ &Apache::lonnet::assignrole($owner_domain,$owner_uname,$courseid,$ccrole,'','','','',$context);
}
#
# Process other reqested users
#
- my @courseroles = qw(st ep ta in cc);
+
+ my @courseroles = qw(st ep ta in);
+ push(@courseroles,$ccrole);
if (&owner_is_dc($owner_uname,$owner_domain,$crsudom)) {
push(@courseroles,'ad');
}
@@ -567,7 +591,7 @@ sub build_course {
}
}
my $firstsec;
- unless (($firstrole eq 'cc') || ($firstrole eq '')) {
+ unless (($firstrole eq $ccrole) || ($firstrole eq '')) {
$firstsec = $details->{'users'}{$userkey}{$firstrole}{'usec'}[0];
}
my $userargs = {
@@ -590,12 +614,18 @@ sub build_course {
'cdom' => $crsudom,
'context' => 'createcourse',
'linefeed' => $linefeed,
- 'role' => $details->{'users'}{$userkey}{'roles'}[0],
+ 'role' => $details->{'users'}{$userkey}{'roles'}[0],
};
+ if ($userargs->{'role'} eq 'st') {
+ if (exists($details->{'users'}{$userkey}{'credits'})) {
+ $userargs->{'credits'} = $details->{'users'}{$userkey}{'credits'};
+ $userargs->{'credits'} =~ s/[^\d\.]//g;
+ }
+ }
$outcome = &LONCAPA::Enrollment::create_newuser($userargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo,$context);
# now add other roles and other sections.
if ($outcome eq 'ok') {
- if ((($firstrole ne 'st') && ($firstrole ne 'cc') && ($firstrole ne '')) && (@{$details->{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) {
+ if ((($firstrole ne 'st') && ($firstrole ne $ccrole) && ($firstrole ne '')) && (@{$details->{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) {
for (my $i=1; $i<@{$details->{'users'}{$userkey}{$firstrole}{'usec'}}; $i++) {
my $curr_role = $firstrole;
my $start = $details->{'users'}{$userkey}{$curr_role}{'start'};
@@ -622,8 +652,13 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
- } elsif ($curr_role eq 'cc') {
+ my $credits;
+ if (exists($details->{'users'}{$userkey}{'credits'})) {
+ $credits = $details->{'users'}{$userkey}{'credits'};
+ $credits =~ s/[^\d\.]//g;
+ }
+ $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context,$credits);
+ } elsif ($curr_role eq $ccrole) {
$url = '/'.$crsudom.'/'.$crsunum;
my $usec = '';
$$output .=
@@ -663,7 +698,12 @@ sub build_course {
if ($usec ne '') {
$url .= '/'.$usec;
}
- $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context);
+ my $credits;
+ if (exists($details->{'users'}{$userkey}{'credits'})) {
+ $credits = $details->{'users'}{$userkey}{'credits'};
+ $credits =~ s/[^\d\.]//g;
+ }
+ $$output .= &Apache::loncommon::commit_studentrole(\$stulogmsg,$userdom,$username,$url,$curr_role,$start,$end,$crsudom,$crsunum,$usec,$context,$credits);
} elsif ((grep(/^\Q$curr_role\E$/,@courseroles)) ||
($curr_role =~ m{^cr/$match_domain/$match_username/[^/]+$})) {
if (@{$details->{'users'}{$userkey}{$curr_role}{'usec'}} > 0) {