--- loncom/interface/loncreatecourse.pm 2014/01/29 18:37:41 1.154 +++ loncom/interface/loncreatecourse.pm 2019/07/26 17:27:44 1.158.2.5 @@ -1,7 +1,7 @@ # The LearningOnline Network # Create a course # -# $Id: loncreatecourse.pm,v 1.154 2014/01/29 18:37:41 bisitz Exp $ +# $Id: loncreatecourse.pm,v 1.158.2.5 2019/07/26 17:27:44 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 @@ -133,6 +137,8 @@ sub print_course_creation_page { } else { my $title_alert = &mt('A Community title is required'); my $coord_alert = &mt('The username of the Coordinator is required'); + &js_escape(\$title_alert); + &js_escape(\$coord_alert); $javascript_validations = qq| function validate(formname) { if (formname.title == '') { @@ -158,7 +164,7 @@ function validate(formname) { 'snid' => "Section Numbers and corresponding LON-CAPA section IDs", 'csli' => "a comma separated list of institutional section numbers, each separated by a colon from the (optional) corresponding section ID to be used in LON-CAPA e.g., 001:1,002:2", 'crcs' => "Crosslisted courses", - 'cscs' => "a comma separated list of course sections crosslisted with the current course, with each entry including the institutional course section name followed by a colon and then the (optional) sectionID to be used in LON-CAPA, e.g., fs03ent231001:ent1,fs03bot231001:bot1,fs03zol231002:zol2", + 'cscs' => "a comma separated list of course sections crosslisted with the current course, with each entry including the institutional course section name followed by a colon and then the (optional) section ID to be used in LON-CAPA, e.g., fs03ent231001:ent1,fs03bot231001:bot1,fs03zol231002:zol2", 'ccre' => "Course credits", 'crcd' => "Create six character course identifier to share with students", 'cred' => "the number of institutional credits students will earn by completing this course", @@ -185,7 +191,8 @@ function validate(formname) { 'oaas' => "Open all assessments", 'mssg' => "Messaging", 'scpf' => "Set course policy feedback to Course Coordinator", - 'scfc' => "Set content feedback to Course Coordinator", + 'scfc' => "Set resource content feedback to Course Coordinator", + 'scof' => "Set course content feedback to Course Coordinator", 'cmmn' => "Communication", 'dsrd' => "Disable student resource discussion", 'dsuc' => "Disable student use of chat rooms", @@ -231,7 +238,8 @@ function validate(formname) { $lt{'navi'} = &mt('Community Contents'); $lt{'cid'} = &mt('Community ID'); $lt{'scpf'} = &mt('Set community policy feedback to Coordinator'); - $lt{'scfc'} = &mt('Set content feedback to Coordinator'); + $lt{'scfc'} = &mt('Set resource content feedback to Coordinator'); + $lt{'scof'} = &mt('Set community content feedback to Coordinator'); $lt{'dsrd'} = &mt('Disable member resource discussion'); $lt{'dsuc'} = &mt('Disable member use of chat rooms'); $lt{'dads'} = &mt('Default Access Dates for Members'); @@ -460,6 +468,10 @@ END .'' .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title($lt{'scof'}) + .'' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_headline() .'
'.&mt('Course identifier to share with students: [_1]',$code).'
' ); } - # Flush the course logs so reverse user roles immediately updated - $r->register_cleanup(\&Apache::lonnet::flushcourselogs); + 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(''.
@@ -732,7 +747,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');
@@ -741,6 +756,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',
@@ -748,7 +767,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.'
@@ -756,7 +775,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.'
@@ -764,7 +783,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.'
@@ -774,7 +793,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 => '',
@@ -835,43 +854,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 = '.&mt('Could not open attributes file.').' '.&mt('No uploaded attributes file found.').' '.&mt('Invalid path to attributes file.').' '.&mt("Your username, domain, and/or your current role's domain are missing or contain invalid characters.").
+ '
'.&mt('No courses created.').'
'.&mt('No courses created.').'
'.&mt('No courses created.').'
'.&mt('No courses created.').'
'.
- &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 {
@@ -1158,7 +1202,7 @@ sub creation_display_filter {
$typename = $typenames->{$type};
}
}
- $output .= ''."\n";
+ $output .= ''."\n";
}
$output .= '';
}
@@ -1245,6 +1289,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;
@@ -1255,14 +1351,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;
@@ -1273,9 +1386,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',),
@@ -1285,21 +1399,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",
@@ -1316,12 +1433,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".'