--- loncom/interface/loncreatecourse.pm 2010/09/20 00:51:14 1.144
+++ loncom/interface/loncreatecourse.pm 2020/05/22 19:57:57 1.158.2.6
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Create a course
#
-# $Id: loncreatecourse.pm,v 1.144 2010/09/20 00:51:14 raeburn Exp $
+# $Id: loncreatecourse.pm,v 1.158.2.6 2020/05/22 19:57:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -82,7 +82,11 @@ use Apache::lonlocal;
use Apache::lonuserutils;
use Apache::lonclonecourse;
use LONCAPA::batchcreatecourse;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
+
+my $registered_flush;
+my $registered_instcats;
+my $modified_dom;
# ===================================================== Phase one: fill-in form
@@ -93,12 +97,13 @@ sub print_course_creation_page {
$crstype = 'Course';
}
my $defdom=$env{'request.role.domain'};
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($defdom);
my %host_servers = &Apache::lonnet::get_servers($defdom,'library');
my $course_home = '';
}
@@ -1211,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;
@@ -1221,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;
@@ -1239,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',),
@@ -1251,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",
@@ -1282,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",
@@ -1304,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'}).'
'.
@@ -1316,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'}).''.
&Apache::loncommon::end_page());
- } elsif (($env{'form.phase'} eq 'requestvalidation') && ($show_all_choices)) {
+ } elsif (($permission->{'create'}) &&
+ ($env{'form.phase'} eq 'requestvalidation') && ($show_all_choices)) {
my $js = &courserequestbrowser_javascript();
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/createcourse?phase=pendingdisplay",
@@ -1329,7 +1504,7 @@ sub handler {
{href=>"/adm/createcourse?phase=requestvalidation",
text=>&mt('Validation Attempted'),},);
my $start_page=&Apache::loncommon::start_page('Requests Validation Result',$js);
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Validation Attempted','Course_Request',undef,'Course_Request');
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Validation Attempted','Course_Requests',undef,'Course_Requests');
$r->print($start_page.$crumbs."\n".''.
&Apache::loncoursequeueadmin::process_official_reqs('domain',$env{'request.role.domain'}).'
'.
&Apache::loncommon::end_page());
@@ -1343,12 +1518,12 @@ sub handler {
'// ]]>'."\n".
'';
my $start_page=&Apache::loncommon::start_page('Course/Community Creation Logs',$js);
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Created Courses/Communities','Creation_Log',undef,'Creation_Log');
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Created Courses/Communities','Course_Creation_Log',undef,'Course_Creation_Log');
$r->print($start_page.$crumbs."\n".'');
&print_creation_logs($r);
$r->print('
'.&Apache::loncommon::end_page());
} else {
- &print_intro_page($r,$show_all_choices);
+ &print_intro_page($r,$show_all_choices,\%cancreate,$permission);
}
} else {
$env{'user.error.msg'}=