'
.&Apache::lonhtmlcommon::start_pick_box()
.&Apache::lonhtmlcommon::row_headline()
@@ -317,8 +333,8 @@ END
$r->print(&Apache::lonhtmlcommon::row_headline()
.'
'.$lt{'iinf'}.' '
.$lt{'stat'}.' '
- .&mt('Default credits can also be specified, if different from the domain defaults (official courses: [_1]; unofficial courses: [_2]).',
- $domdefaults{'officialcredits'},$domdefaults{'unofficialcredits'})
+ .&mt('Default credits can also be specified, if different from the domain defaults (official courses: [_1]; unofficial courses: [_2]; textbook courses: [_3]).',
+ $domdefaults{'officialcredits'},$domdefaults{'unofficialcredits'},$domdefaults{'textbookcredits'})
.&Apache::lonhtmlcommon::row_closure()
.&Apache::lonhtmlcommon::row_title($lt{'ccod'})
@@ -336,13 +352,20 @@ END
.'
('.$lt{'cscs'}.')'
.&Apache::lonhtmlcommon::row_closure()
);
- if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
+ if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
$r->print(&Apache::lonhtmlcommon::row_title($lt{'ccre'})
.'
'
.'
('.$lt{'cred'}.')'
.&Apache::lonhtmlcommon::row_closure()
);
}
+ $r->print(&Apache::lonhtmlcommon::row_title($lt{'crcd'})
+ .'
'
+ .' '.&mt('Yes').(' 'x2)
+ .' '.&mt('No')
+ .'
+ .&Apache::lonhtmlcommon::row_closure()
+ );
}
# Table: New Course / Clone Course
$r->print(&Apache::lonhtmlcommon::row_headline()
@@ -388,7 +411,7 @@ END
.&Apache::lonhtmlcommon::row_closure(1)
.&Apache::lonhtmlcommon::end_pick_box()
- .'
'
+ .'
'
# Clone Course:
.'
'
@@ -438,7 +461,10 @@ END
.&Apache::lonhtmlcommon::row_closure()
.&Apache::lonhtmlcommon::row_title($lt{'oaas'})
- .' '
+ .''
+ .' '.$lt{'no'}.' '.(' 'x2)
+ .' '.$lt{'yes'}.' '.', '
+ .$lt{'sta'}.' '.$openallfrom.' '
.&Apache::lonhtmlcommon::row_closure()
.&Apache::lonhtmlcommon::row_headline()
@@ -453,6 +479,10 @@ END
.' '
.&Apache::lonhtmlcommon::row_closure()
+ .&Apache::lonhtmlcommon::row_title($lt{'scof'})
+ .' '
+ .&Apache::lonhtmlcommon::row_closure()
+
.&Apache::lonhtmlcommon::row_headline()
.''.$lt{'cmmn'}.' '
.&Apache::lonhtmlcommon::row_closure()
@@ -548,7 +578,8 @@ END
- '
+
+
'
);
} elsif ($crstype eq 'Community') {
$r->print('
@@ -570,7 +601,7 @@ sub create_course {
my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
my $crstype = 'Community';
- my ($enrollstart,$enrollend,$startaccess,$endaccess);
+ my ($enrollstart,$enrollend,$startaccess,$endaccess,$openallfrom);
my %domdefaults =
&Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
@@ -581,6 +612,7 @@ sub create_course {
}
$startaccess = &Apache::lonhtmlcommon::get_date_from_form('startaccess');
$endaccess = &Apache::lonhtmlcommon::get_date_from_form('endaccess');
+ $openallfrom = &Apache::lonhtmlcommon::get_date_from_form('openallfrom');
my $autharg;
my $authtype;
@@ -639,20 +671,26 @@ sub create_course {
endaccess => $endaccess,
setpolicy => $env{'form.setpolicy'},
setcontent => $env{'form.setcontent'},
+ setcomment => $env{'form.setcomment'},
reshome => $env{'form.reshome'},
setkeys => $env{'form.setkeys'},
keyauth => $env{'form.keyauth'},
disresdis => $env{'form.disresdis'},
disablechat => $env{'form.disablechat'},
openall => $env{'form.openall'},
+ openallfrom => $openallfrom,
firstres => $env{'form.firstres'}
};
if (($crstype eq 'Course') &&
- ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'})) {
+ ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'})) {
$args->{'defaultcredits'} = $env{'form.defaultcredits'};
}
+ if ($env{'form.uniquecode'}) {
+ $args->{'uniquecode'} = 1;
+ }
+
#
# Verify data
#
@@ -681,12 +719,12 @@ sub create_course {
,$env{'form.course_home'}.&Apache::loncommon::end_page()));
return;
}
- my ($courseid,$crsudom,$crsunum);
+ my ($courseid,$crsudom,$crsunum,$code);
my ($success,$output) =
&Apache::loncommon::construct_course($args,\$logmsg,\$courseid,
\$crsudom,\$crsunum,
$env{'user.domain'},
- $env{'user.name'},'dc_create');
+ $env{'user.name'},'dc_create',undef,undef,\$code);
$r->print($output);
if ($success) {
#
@@ -706,8 +744,15 @@ sub create_course {
$r->print(
''.&mt('Manage Access Keys').'
');
}
- # Flush the course logs so reverse user roles immediately updated
- $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
+ if ($code) {
+ $r->print(
+ ''.&mt('Course identifier to share with students: [_1]',$code).'
'
+ );
+ }
+ if ($env{'form.crscode'} ne '') {
+ &Apache::lonnet::devalidate_cache_new('instcats',$crsudom);
+ }
+ ®ister_cleanups($r,$crsudom,$env{'form.crscode'});
$r->print(''.&mt('Roles will be active at next login').'.
');
}
$r->print(''.
@@ -716,7 +761,7 @@ sub create_course {
}
sub print_intro_page {
- my ($r,$show_all_choices) = @_;
+ my ($r,$show_all_choices,$cancreate,$permission) = @_;
my $start_page =
&Apache::loncommon::start_page('Create a New Course or Community');
my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses');
@@ -725,6 +770,10 @@ sub print_intro_page {
my $helplink=&Apache::loncommon::help_open_topic('Create_Course_Community',&mt('Help on Creating Courses and Communities'));
# Create menu
+ my $approve = 'Display requests awaiting approval';
+ if ($permission->{'create'}) {
+ $approve = 'Approve or reject requests';
+ }
my @menu;
@menu =
({ categorytitle => 'Course/Community Creation',
@@ -732,7 +781,7 @@ sub print_intro_page {
{
linktext => 'Create a single course',
url => '/adm/createcourse?phase=courseone',
- permission => 1,
+ permission => $permission->{'create'},
#help => '',
icon => 'crsnew.png',
linktitle => 'Create a new course by completing an online form.'
@@ -740,7 +789,7 @@ sub print_intro_page {
{
linktext => 'Create a single community',
url => '/adm/createcourse?phase=groupone',
- permission => $show_all_choices,
+ permission => $permission->{'create'} && $cancreate->{'Community'},
#help => '',
icon => 'crsnew.png',
linktitle => 'Create a new collaborative community by completing an online form.'
@@ -748,7 +797,7 @@ sub print_intro_page {
{
linktext => 'Create courses/communities by uploading an attributes file',
url => '/adm/createcourse?phase=batchone',
- permission => 1,
+ permission => $permission->{'create'},
help => 'Batch_Creation',
icon => 'uplcrs.png',
linktitle => 'Upload an attributes file containing specifications for one or more courses or communities in XML format.'
@@ -758,7 +807,7 @@ sub print_intro_page {
{ categorytitle => 'Course/Community Requests',
items => [
{
- linktext => 'Approve or reject requests',
+ linktext => $approve,
url => '/adm/createcourse?phase=requestdisplay',
permission => $show_all_choices,
#help => '',
@@ -819,43 +868,68 @@ sub upload_batchfile {
sub process_batchfile {
my $r = shift;
- my $start_page =
- &Apache::loncommon::start_page('Create a New Course or Community');
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
- my $end_page =
- &Apache::loncommon::end_page();
my $defdom=$env{'request.role.domain'};
- my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
- 'batchupload',undef,undef,
- undef,undef,$defdom);
- my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
- my ($result,$logmsg);
- if (-e "$batchfilepath") {
- open(FILE,"<$batchfilepath");
- my @buffer = ;
- close(FILE);
- if ((defined($filename)) && (defined($batchdir))) {
- my @requests = ($filename);
- my %courseids = ();
- ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
- \@requests,\%courseids,'web',$defdom,
- $env{'user.name'},$env{'user.domain'});
- if ($result) {
- if (!-e "$batchdir/processed") {
- mkdir("$batchdir/processed", 0755);
- open(FILE,">$batchdir/processed/$filename");
- print FILE @buffer;
+ my $uname = $env{'user.name'};
+ my $udom = $env{'user.domain'};
+ my $dir = &LONCAPA::tempdir().'addcourse';
+ my ($result,$logmsg,$keysmsg,$codesref,$instcodesref);
+ if (($defdom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/) && ($udom =~/^$match_domain$/)) {
+ my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
+ 'batchupload',undef,undef,
+ undef,undef,$defdom);
+ if ($batchfilepath =~ m{^(\Q$dir/$defdom/web/$uname\E_\Q$udom\E)/pending/([^/]+)$}) {
+ my ($batchdir,$filename) = ($1,$2);
+ if (-e "$batchfilepath") {
+ if (open(FILE,"<",$batchfilepath)) {
+ my @buffer = ;
close(FILE);
- if (-e "$batchdir/processed/$filename") {
- unlink("$batchdir/pending/$filename");
+ if ((defined($filename)) && (defined($batchdir))) {
+ my @requests = ($filename);
+ my %courseids = ();
+ ($result,$logmsg,$keysmsg,$codesref,$instcodesref) =
+ &LONCAPA::batchcreatecourse::create_courses(
+ \@requests,\%courseids,'web',$defdom,
+ $uname,$udom);
+ if (keys(%courseids) > 0) {
+ if (!-e "$batchdir/processed") {
+ mkdir("$batchdir/processed", 0755);
+ }
+ if (-d "$batchdir/processed") {
+ if (open(FILE,">","$batchdir/processed/$filename")) {
+ print FILE @buffer;
+ close(FILE);
+ }
+ }
+ if (-e "$batchdir/processed/$filename") {
+ unlink("$batchdir/pending/$filename");
+ }
+ my $updatecats;
+ if ((ref($instcodesref) eq 'HASH') && (keys(%{$instcodesref}) > 0)) {
+ &Apache::lonnet::devalidate_cache_new('instcats',$defdom);
+ $updatecats = 1;
+ }
+ ®ister_cleanups($r,$defdom,$updatecats);
+
+ }
}
+ } else {
+ $result = ''.&mt('Could not open attributes file.').' '.&mt('No courses created.').'
';
}
+ } else {
+ $result = ''.&mt('No uploaded attributes file found.').' '.&mt('No courses created.').'
';
}
+ } else {
+ $result = ''.&mt('Invalid path to attributes file.').' '.&mt('No courses created.').'
';
}
+ } else {
+ $result = ''.&mt("Your username, domain, and/or your current role's domain are missing or contain invalid characters.").
+ ' '.&mt('No courses created.').'
';
}
- $r->print($start_page.$crumbs.$logmsg.$result.''.
- &mt('Creation options menu').' '.$end_page);
-
+ $r->print(&Apache::loncommon::start_page('Create a New Course, Community or Placement Test').
+ &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses').
+ $logmsg.$result.''.
+ &mt('Creation options menu').' '.
+ &Apache::loncommon::end_page());
}
sub courserequestbrowser_javascript {
@@ -1142,7 +1216,7 @@ sub creation_display_filter {
$typename = $typenames->{$type};
}
}
- $output .= ''.$typename.' '."\n";
+ $output .= ''.&mt($typename).' '."\n";
}
$output .= '
';
}
@@ -1229,6 +1303,58 @@ ENDJS
}
+sub get_permission {
+ my ($dom) = @_;
+ my ($allowed,%permission);
+ if (&Apache::lonnet::allowed('ccc',$dom)) {
+ $allowed = 1;
+ %permission = (
+ create => 1,
+ );
+ } elsif (&Apache::lonnet::allowed('dcc',$dom)) {
+ $allowed = 1;
+ }
+ return ($allowed,\%permission);
+}
+
+sub register_cleanups {
+ my ($r,$cdom,$updatecats) = @_;
+ # Flush the course logs so reverse user roles immediately updated
+ unless ($registered_flush) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&Apache::lonnet::flushcourselogs,@{$handlers}]);
+ $registered_flush=1;
+ }
+ # Update cache of self-cataloging courses on institution's server(s).
+ if ($updatecats) {
+ if (&Apache::lonnet::shared_institution($cdom)) {
+ unless ($registered_instcats) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
+ $registered_instcats=1;
+ $modified_dom = $cdom;
+ }
+ }
+ }
+ return;
+}
+
+sub devalidate_remote_instcats {
+ if ($modified_dom ne '') {
+ my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
+ my %thismachine;
+ map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
+ if (keys(%servers)) {
+ foreach my $server (keys(%servers)) {
+ next if ($thismachine{$server});
+ &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
+ }
+ }
+ $modified_dom = '';
+ }
+ return;
+}
+
# ===================================================================== Handler
sub handler {
my $r = shift;
@@ -1239,14 +1365,31 @@ sub handler {
return OK;
}
- my $show_all_choices = 0;
- my $primary_rev = &Apache::lonnet::get_server_loncaparev($env{'request.role.domain'});
- if (($primary_rev ne 'refused') && ($primary_rev ne 'error') &&
- ($primary_rev ne 'unknown_cmd') && ($primary_rev ne 'no_such_host')) {
- $show_all_choices = 1;
- }
+ $registered_flush = 0;
+ $registered_instcats = 0;
+ $modified_dom = '';
+
+ my ($allowed,$permission) = &get_permission($env{'request.role.domain'});
+ if ($allowed) {
+ my $show_all_choices = 0;
+ my $primary_rev = &Apache::lonnet::get_server_loncaparev($env{'request.role.domain'});
+ my %cancreate = (
+ Community => 0,
+ );
+ if (($primary_rev ne 'refused') && ($primary_rev ne 'error') &&
+ ($primary_rev ne 'unknown_cmd') && ($primary_rev ne 'no_such_host')) {
+ $show_all_choices = 1;
+ my ($primary_major,$primary_minor) = split(/\./,$primary_rev);
+ foreach my $key (keys(%cancreate)) {
+ my ($needsmajor,$needsminor) =
+ split(/\./,$Apache::lonnet::needsrelease{'course:crstype:'.$key});
+ unless (($needsmajor > $primary_major) ||
+ (($needsmajor == $primary_major) && ($needsminor > $primary_minor))) {
+ $cancreate{$key} = 1;
+ }
+ }
+ }
- if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
@@ -1257,9 +1400,10 @@ sub handler {
({href=>"/adm/createcourse",
text=>"Creation Options",
faq=>79,bug=>'Dom Coord Interface',});
- if (($env{'form.phase'} eq 'coursetwo') ||
- (($env{'form.phase'} eq 'grouptwo') &&
- ($show_all_choices))) {
+ if (($permission->{'create'}) &&
+ (($env{'form.phase'} eq 'coursetwo') ||
+ (($env{'form.phase'} eq 'grouptwo') &&
+ ($cancreate{'Community'})))) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
text=>&mt('[_1] Creation Settings',),
@@ -1269,21 +1413,24 @@ sub handler {
text=>"Creation Outcome",
faq=>9,bug=>'Dom Coord Interface',});
&create_course($r);
- } elsif (($env{'form.phase'} eq 'courseone') ||
- (($env{'form.phase'} eq 'groupone') &&
- ($show_all_choices))) {
+ } elsif (($permission->{'create'}) &&
+ (($env{'form.phase'} eq 'courseone') ||
+ (($env{'form.phase'} eq 'groupone') &&
+ ($cancreate{'Community'})))) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/createcourse?phase=$env{'form.phase'}",
text=>&mt('[_1] Creation Settings',),
faq=>9,bug=>'Dom Coord Interface',});
&print_course_creation_page($r);
- } elsif ($env{'form.phase'} eq 'batchone') {
+ } elsif (($permission->{'create'}) &&
+ ($env{'form.phase'} eq 'batchone')) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/createcourse?phase=$env{'form.phase'}",
text=>"Upload Description File",
faq=>9,bug=>'Dom Coord Interface',});
&upload_batchfile($r);
- } elsif ($env{'form.phase'} eq 'batchtwo') {
+ } elsif (($permission->{'create'}) &&
+ ($env{'form.phase'} eq 'batchtwo')) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/createcourse?phase=$env{'form.prevphase'}",
text=>"Upload Description File",
@@ -1300,12 +1447,17 @@ sub handler {
faq=>9,bug=>'Dom Coord Interface',});
my $js = &courserequestbrowser_javascript();
my $start_page=&Apache::loncommon::start_page('Display Requests',$js);
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Display Requests','Course_Request',undef,'Course_Request');
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Display Requests','Course_Requests',undef,'Course_Requests');
+ my $context = 'domain';
+ unless ($permission->{'create'}) {
+ $context = 'helpdesk';
+ }
$r->print($start_page.$crumbs."\n".'
'.
&Apache::loncoursequeueadmin::display_queued_requests(
- 'domain',$env{'request.role.domain'}).'
'.
+ $context,$env{'request.role.domain'}).'
'.
&Apache::loncommon::end_page());
- } elsif (($env{'form.phase'} eq 'requestchange') && ($show_all_choices)) {
+ } elsif (($permission->{'create'}) &&
+ ($env{'form.phase'} eq 'requestchange') && ($show_all_choices)) {
if ($env{'form.queue'} eq 'pending') {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/createcourse?phase=pendingdisplay",
@@ -1322,7 +1474,7 @@ sub handler {
text=>&mt('[_1] Requests Updated',),
faq=>9,bug=>'Dom Coord Interface',},);
my $start_page=&Apache::loncommon::start_page('Update Requests Result');
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Requests Updated','Course_Request',undef,'Course_Request');
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Requests Updated','Course_Requests',undef,'Course_Requests');
$r->print($start_page.$crumbs."\n".''.
&Apache::loncoursequeueadmin::update_request_queue(
'domain',$env{'request.role.domain'}).'
'.
@@ -1334,12 +1486,17 @@ sub handler {
faq=>9,bug=>'Dom Coord Interface',});
my $js = &courserequestbrowser_javascript();
my $start_page=&Apache::loncommon::start_page('Display Pending Queue',$js);
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Display Pending Queue','Course_Request',undef,'Course_Request');
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Display Pending Queue','Course_Requests',undef,'Course_Requests');
+ my $context = 'pending';
+ unless ($permission->{'create'}) {
+ $context = 'displaypending';
+ }
$r->print($start_page.$crumbs."\n".''.
&Apache::loncoursequeueadmin::display_queued_requests(
- 'pending',$env{'request.role.domain'}).'
'.
+ $context,$env{'request.role.domain'}).'