version 1.5, 2005/06/01 19:20:32
|
version 1.12, 2006/05/26 15:37:14
|
Line 36 use Apache::loncreatecourse;
|
Line 36 use Apache::loncreatecourse;
|
use Apache::loncreateuser; |
use Apache::loncreateuser; |
use Apache::lonlocal; |
use Apache::lonlocal; |
|
|
|
use strict; |
|
|
# Collection of routines used for batch creation of courses and users. |
# Collection of routines used for batch creation of courses and users. |
# &create_courses() should be called by an Autocreate.pl |
# &create_courses() should be called by an Autocreate.pl |
# script via a cron entry, or alternatively from a web page, after upload |
# script via a cron entry, or alternatively from a web page, after upload |
Line 184 sub create_courses {
|
Line 186 sub create_courses {
|
my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf'); |
# Get role names |
# Get role names |
my %longroles = (); |
my %longroles = (); |
open(FILE,"<$perlvarref{'lonTabDir'}.'/rolesplain.tab"); |
open(FILE,"<$$perlvarref{'lonTabDir'}.'/rolesplain.tab"); |
my @rolesplain = <FILE>; |
my @rolesplain = <FILE>; |
close(FILE); |
close(FILE); |
foreach (@rolesplain) { |
foreach (@rolesplain) { |
Line 376 sub parse_coursereqs {
|
Line 378 sub parse_coursereqs {
|
######################################################### |
######################################################### |
|
|
sub build_course { |
sub build_course { |
my ($cdom,$num,$context,$details,$longoles,$logmsg,$newusermsg,$addresult,$enrollcount,$output,$keysmsg,$udom,$uname) = @_; |
my ($cdom,$num,$context,$details,$longroles,$logmsg,$newusermsg,$addresult,$enrollcount,$output,$keysmsg,$udom,$uname) = @_; |
my $owner_uname = $$details{$num}{'owner'}; |
my $owner_uname = $$details{$num}{'owner'}; |
my $owner_domain = $$details{$num}{'domain'}; |
my $owner_domain = $$details{$num}{'domain'}; |
my $owner = $owner_uname.':'.$owner_domain; |
my $owner = $owner_uname.':'.$owner_domain; |
Line 420 sub build_course {
|
Line 422 sub build_course {
|
my $ownerargs = {'auth' => $$details{$num}{'ownerauthtype'}, |
my $ownerargs = {'auth' => $$details{$num}{'ownerauthtype'}, |
'authparam' => $$details{$num}{'ownerauthparam'}, |
'authparam' => $$details{$num}{'ownerauthparam'}, |
'emailenc' => $$details{$num}{'emailenc'}, |
'emailenc' => $$details{$num}{'emailenc'}, |
'dom' => $$details{$num}{'domain'}, |
'udom' => $$details{$num}{'domain'}, |
'uname' => $$details{$num}{'owner'}, |
'uname' => $$details{$num}{'owner'}, |
'pid' => '', |
'pid' => $$details{$num}{'users'}{$owner}{'studentID'}, |
'first' => $$details{$num}{'users'}{$owner}{'first'}, |
'first' => $$details{$num}{'users'}{$owner}{'firstname'}, |
'middle' => $$details{$num}{'users'}{$owner}{'middle'}, |
'middle' => $$details{$num}{'users'}{$owner}{'middlename'}, |
'last' => $$details{$num}{'users'}{$owner}{'last'}, |
'last' => $$details{$num}{'users'}{$owner}{'lastname'}, |
'gene' => $$details{$num}{'users'}{$owner}{'gene'}, |
'gene' => $$details{$num}{'users'}{$owner}{'generation'}, |
'usec' => '', |
'usec' => '', |
'end' => '', |
'end' => '', |
'start' => '', |
'start' => '', |
Line 436 sub build_course {
|
Line 438 sub build_course {
|
'linefeed' => $linefeed, |
'linefeed' => $linefeed, |
'role' => 'cc', |
'role' => 'cc', |
}; |
}; |
$outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,$courseinfo); |
$outcome = &LONCAPA::Enrollment::create_newuser($ownerargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo); |
} else { |
} else { |
$outcome = 'ok'; |
$outcome = 'ok'; |
} |
} |
|
|
my $courseargs = { |
if ($outcome eq 'ok') { |
|
my $courseargs = { |
ccuname => $$details{$num}{'owner'}, |
ccuname => $$details{$num}{'owner'}, |
ccdomain => $$details{$num}{'domain'}, |
ccdomain => $$details{$num}{'domain'}, |
cdescr => $$details{$num}{'title'}, |
cdescr => $$details{$num}{'title'}, |
Line 468 sub build_course {
|
Line 471 sub build_course {
|
enrollend => $$details{$num}{'enrollend'}, |
enrollend => $$details{$num}{'enrollend'}, |
startaccess => $$details{$num}{'accessstart'}, |
startaccess => $$details{$num}{'accessstart'}, |
endaccess => $$details{$num}{'accessend'}, |
endaccess => $$details{$num}{'accessend'}, |
setpolicy => $Sdetails{$num}{'setpolicy'}, |
setpolicy => $$details{$num}{'setpolicy'}, |
setcontent => $$details{$num}{'setcontent'}, |
setcontent => $$details{$num}{'setcontent'}, |
reshome => $reshome, |
reshome => $reshome, |
setkeys => $$details{$num}{'setkeys'}, |
setkeys => $$details{$num}{'setkeys'}, |
Line 479 sub build_course {
|
Line 482 sub build_course {
|
firstres => $firstres |
firstres => $firstres |
}; |
}; |
|
|
if ($outcome eq 'ok') { |
|
my %host_servers = &Apache::loncommon::get_library_servers($cdom); |
my %host_servers = &Apache::loncommon::get_library_servers($cdom); |
if (! exists($host_servers{$$details{$num}{'coursehome'}})) { |
if (! exists($host_servers{$$details{$num}{'coursehome'}})) { |
$$logmsg .= &mt('Invalid home server for course').': '.$$details{$num}{'coursehome'}; |
$$logmsg .= &mt('Invalid home server for course').': '.$$details{$num}{'coursehome'}; |
Line 508 sub build_course {
|
Line 510 sub build_course {
|
my ($username,$userdom) = split/:/,$userkey; |
my ($username,$userdom) = split/:/,$userkey; |
if (&Apache::lonnet::homeserver($username,$userdom) eq 'no_host') { # Add user if no account |
if (&Apache::lonnet::homeserver($username,$userdom) eq 'no_host') { # Add user if no account |
my $firstrole = $$details{$num}{'users'}{$userkey}{'roles'}[0]; |
my $firstrole = $$details{$num}{'users'}{$userkey}{'roles'}[0]; |
my $firssec = $$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}[0]; |
my $firstsec = $$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}[0]; |
my $userargs = { |
my $userargs = { |
'auth' => $$details{$num}{'users'}{$userkey}{'authtype'}, |
'auth' => $$details{$num}{'users'}{$userkey}{'authtype'}, |
'authparam' => $$details{$num}{'users'}{$userkey}{'autharg'}, |
'authparam' => $$details{$num}{'users'}{$userkey}{'autharg'}, |
'emailenc' => $$details{$num}{'users'}{$userkey}{'emailenc'}, |
'emailenc' => $$details{$num}{'users'}{$userkey}{'emailenc'}, |
'dom' => $userdom, |
'udom' => $userdom, |
'uname' => $username, |
'uname' => $username, |
'pid' => $$details{$num}{'users'}{$userkey}{'studentID'}, |
'pid' => $$details{$num}{'users'}{$userkey}{'studentID'}, |
'first' => $$details{$num}{'users'}{$userkey}{'first'}, |
'first' => $$details{$num}{'users'}{$userkey}{'firstname'}, |
'middle' => $$details{$num}{'users'}{$userkey}{'middle'}, |
'middle' => $$details{$num}{'users'}{$userkey}{'middlename'}, |
'last' => $$details{$num}{'users'}{$userkey}{'last'}, |
'last' => $$details{$num}{'users'}{$userkey}{'lastname'}, |
'gene' => $$details{$num}{'users'}{$userkey}{'gene'}, |
'gene' => $$details{$num}{'users'}{$userkey}{'generation'}, |
'usec' => $firstsec, |
'usec' => $firstsec, |
'end' => $$details{$num}{'users'}{$userkey}{'end'}, |
'end' => $$details{$num}{'users'}{$userkey}{'end'}, |
'start' => $$details{$num}{'users'}{$userkey}{'start'}, |
'start' => $$details{$num}{'users'}{$userkey}{'start'}, |
'emailaddr' => $$details{$num}{'users'}{$userkey}{'email'}, |
'emailaddr' => $$details{$num}{'users'}{$userkey}{'emailaddr'}, |
'cid' => $courseid, |
'cid' => $courseid, |
|
'crs' => $crsunum, |
|
'cdom' => $crsudom, |
'context' => 'createcourse', |
'context' => 'createcourse', |
'linefeed' => $linefeed, |
'linefeed' => $linefeed, |
'role' => $$details{$num}{'users'}{$userkey}{'roles'}[0], |
'role' => $$details{$num}{'users'}{$userkey}{'roles'}[0], |
}; |
}; |
$outcome = &LONCAPA::Enrollment::create_newuser($userargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,$courseinfo); |
$outcome = &LONCAPA::Enrollment::create_newuser($userargs,$logmsg,$newusermsg,$enrollcount,$addresult,$longroles,\%courseinfo); |
# now add other roles and other sections. |
# now add other roles and other sections. |
if ($outcome eq 'ok') { |
if ($outcome eq 'ok') { |
if (($firstrole ne 'st') && (@{$$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) { |
if (($firstrole ne 'st') && (@{$$details{$num}{'users'}{$userkey}{$firstrole}{'usec'}} > 1)) { |
Line 625 sub process_date {
|
Line 629 sub process_date {
|
if ($timestr !~ /:/) { |
if ($timestr !~ /:/) { |
$timestamp = ''; |
$timestamp = ''; |
} else { |
} else { |
my @entries = split/:/,$timestr; |
my @entries = split(/:/,$timestr); |
for (my $j=0; $j<@entries; $j++) { |
for (my $j=0; $j<@entries; $j++) { |
if ( length($entries[$j]) > 1 ) { |
if ( length($entries[$j]) > 1 ) { |
$entries[$j] =~ s/^0//; |
$entries[$j] =~ s/^0//; |
} |
} |
|
$entries[$j] =~ s/\D//g; |
|
if ($entries[$j] < 0) { |
|
$entries[$j] = 0; |
|
} |
} |
} |
if ($entries[1] > 0) { |
if ($entries[1] > 0) { |
$entries[1] = $entries[1] - 1; |
$entries[1] = $entries[1] - 1; |
} |
} |
|
if ($entries[5] > 60) { |
|
$entries[5] = 60; |
|
} |
|
if ($entries[4] > 59) { |
|
$entries[4] = 59; |
|
} |
|
if ($entries[3] > 23) { |
|
$entries[3] = 23; |
|
} |
|
if ($entries[2] > 31) { |
|
$entries[2] = 31; |
|
} |
|
if ($entries[1] > 11) { |
|
$entries[1] = 11; |
|
} |
|
if ($entries[2] == 31) { |
|
if (($entries[1] == 3) || ($entries[1] == 5) || |
|
($entries[1] == 8) || ($entries[1] == 10)) { |
|
$entries[2] = 30; |
|
} |
|
} |
|
if ($entries[1] == 1) { |
|
if ($entries[2] > 29) { |
|
$entries[2] = 29; |
|
} |
|
if ($entries[2] == 29) { |
|
if ($entries[0]%4 != 0) { |
|
$entries[2] == 28; |
|
} elsif ( $entries[0]%100 == 0 |
|
&& $entries[0]%400 != 0) { |
|
$entries[2] == 28; |
|
} |
|
} |
|
} |
$timestamp = timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]); |
$timestamp = timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]); |
} |
} |
return $timestamp; |
return $timestamp; |