--- loncom/interface/loncreatecourse.pm 2010/05/14 18:29:52 1.138 +++ loncom/interface/loncreatecourse.pm 2021/08/31 17:23:27 1.176 @@ -1,7 +1,7 @@ # The LearningOnline Network # Create a course # -# $Id: loncreatecourse.pm,v 1.138 2010/05/14 18:29:52 bisitz Exp $ +# $Id: loncreatecourse.pm,v 1.176 2021/08/31 17:23:27 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -80,9 +80,12 @@ use Apache::loncommon; use Apache::londocs; 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 @@ -91,19 +94,23 @@ sub print_course_creation_page { my $crstype = 'Community'; if ($env{'form.phase'} eq 'courseone') { $crstype = 'Course'; + } elsif ($env{'form.phase'} eq 'placementone') { + $crstype = 'Placement'; } 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 = '\n"; - my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain'); + my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom); + my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain',undef,undef,undef,$trusted,$untrusted); my $cloneform=&Apache::loncommon::select_dom_form ($env{'request.role.domain'},'clonedomain'). &Apache::loncommon::selectcourse_link @@ -115,7 +122,9 @@ sub print_course_creation_page { my $endtime = time+(6*30*24*60*60); # 6 months from now, approx my $access_table = &Apache::lonuserutils::date_setting_table($starttime, $endtime,'create_defaultdates'); - if ($crstype eq 'Course') { + my $openallfrom = + &Apache::lonhtmlcommon::date_setter('ccrs','openallfrom',$starttime); + if (($crstype eq 'Course') || ($crstype eq 'Placement')) { $enroll_table = &Apache::lonuserutils::date_setting_table($starttime, $endtime,'create_enrolldates'); ($krbdef,$krbdefdom) = @@ -132,6 +141,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 == '') { @@ -154,11 +165,13 @@ function validate(formname) { 'iinf' => "Institutional Information", 'stat' => "The following entries will be used to identify the course according to the naming scheme adopted by your institution. Your choices will be used to map an internal LON-CAPA course ID to the corresponding course section ID(s) used by the office responsible for providing official class lists for courses at your institution. This mapping is required if you choose to employ automatic population of class lists.", 'ccod' => "Course Code", - 'toin' => "to interface with institutional data, e.g., fs03glg231 for Fall 2003 Geology 231", '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", 'crco' => "Course Content", 'cncr' => "Completely new course", 'cecr' => "Clone an existing course", @@ -178,11 +191,17 @@ function validate(formname) { 'ncd' => "Do not clone date parameters", 'prd' => 'Clone date parameters as-is', 'shd' => 'Shift date parameters by number of days', + 'dpl' => 'URL shortcuts (for deep linking)', + 'nsl' => 'Do not clone URL shortcuts', + 'tsl' => 'Transfer URL shortcuts from existing course to new course', + 'csl' => 'Create new URL shortcuts in new course', 'assp' => "Assessment Parameters", 'oaas' => "Open all assessments", + 'sta' => "starting from:", '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", @@ -203,16 +222,18 @@ function validate(formname) { 'psam' => "Authentication mechanism", 'pcda' => "Default authentication method for new users added to this domain by the automated enrollment process", 'nech' => "Notification of enrollment changes", - 'nccl' => "Notification to course coordinator via LON-CAPA message when enrollment changes occur during the automated update?", - 'ndcl' => "Notification to domain coordinator via LON-CAPA message when enrollment changes occur during the automated update?", 'irsp' => "Include retrieval of student photographs?", 'rshm' => 'Resource Space Home', 'cgrs' => "Course Group Settings", 'cgrq' => 'Set a quota for the total disk space available for storage of course group portfolio files', 'opco' => 'Open Course', 'opcm' => 'Open Community', + 'oppt' => 'Open Placement Test', ); $lt{'kaut'} = &mt('Key authority ([_1]id:domain[_2]) if other than course','',''); + $lt{'toin'} = &mt('to interface with institutional data, e.g., [_1]fs13glg231[_2] for [_3]Fall 2013 Geology 231[_4]','','','',''); + $lt{'nccl'} = &mt('Notification to [_1]course coordinator[_2] via LON-CAPA message when enrollment changes occur during the automated update?','',''); + $lt{'ndcl'} = &mt('Notification to [_1]domain coordinator[_2] via LON-CAPA message when enrollment changes occur during the automated update?','',''); if ($crstype eq 'Community') { $lt{'cinf'} = &mt('Community Information'); @@ -227,7 +248,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'); @@ -238,9 +260,25 @@ function validate(formname) { $lt{'cc'} = &mt('(will be assigned Coordinator role)'); $lt{'cgrs'} = &mt('Community Group Settings'); $lt{'cgrq'} = &mt('Set a quota for the total disk space available for storage of community group portfolio files'); + $lt{'tsl'} = &mt('Transfer URL shortcuts from existing community to new community'); + $lt{'csl'} = &mt('Create new URL shortcuts in new community'); + } elsif ($crstype eq 'Placement') { + $lt{'cinf'} = &mt('Placement Test Information'); + $lt{'ctit'} = &mt('Placement Test Title'); + $lt{'chsr'} = &mt('Placement Test Home Server'); + $lt{'cidn'} = &mt('Placement Test ID/Number'); + $lt{'crco'} = &mt('Placement Test Content'); + $lt{'cncr'} = &mt('Completely new placement test'); + $lt{'cecr'} = &mt('Clone an existing placement test'); + $lt{'sacr'} = &mt('Do NOT generate as standard placement test'); + $lt{'stco'} = &mt('standard placement tests only'); + $lt{'navi'} = &mt('Placement Test Contents'); + $lt{'cid'} = &mt('Placement Test ID'); } my $js = < +// $coursebrowserjs END @@ -266,6 +306,7 @@ END my %titles = &Apache::lonlocal::texthash( courseone => 'Create a New Course', groupone => 'Create a New Community', + placementone=> 'Create a New Placement Test', ); my $start_page = &Apache::loncommon::start_page($titles{$env{'form.phase'}},$js); @@ -299,7 +340,7 @@ END .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_title($lt{'ctit'}) - .'' + .'' .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_title($lt{'chsr'}) @@ -310,12 +351,16 @@ END .'' .&Apache::lonhtmlcommon::row_closure() ); - if ($crstype eq 'Course') { + if (($crstype eq 'Course') || ($crstype eq 'Placement')) { $r->print(&Apache::lonhtmlcommon::row_headline() .'

'.$lt{'iinf'}.'

' - .$lt{'stat'} - .&Apache::lonhtmlcommon::row_closure() - + .$lt{'stat'}); + if ($crstype eq 'Course') { + $r->print(' ' + .&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'})); + } + $r->print(&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_title($lt{'ccod'}) .'' .'
('.$lt{'toin'}.')' @@ -331,8 +376,26 @@ END .'
('.$lt{'cscs'}.')' .&Apache::lonhtmlcommon::row_closure() ); + if (($crstype eq 'Course') && ($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() + ); + } + my $blankchk; + if ($crstype eq 'Placement') { + $blankchk = ' checked="checked"'; } - # Table: New Course / Clone Course $r->print(&Apache::lonhtmlcommon::row_headline() .'

'.$lt{'crco'}.'

' @@ -357,21 +420,27 @@ END .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_title($lt{'fres'}) .'' - .' ' - .''); + if ($crstype eq 'Community') { + $r->print(' '); + } elsif ($crstype eq 'Course') { + $r->print(' ' .' ' .'' - .'
('.$lt{'stco'}.')' + .''); + } + my $tinyurlhelp=&Apache::loncommon::help_open_topic('Clone_Tiny_URLs'); + $r->print('
('.$lt{'stco'}.')' .&Apache::lonhtmlcommon::row_closure(1) .&Apache::lonhtmlcommon::end_pick_box() - .' ' + .' ' # Clone Course: .'' @@ -396,10 +465,21 @@ END .'' - .' ' + .' ' + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title($tinyurlhelp.$lt{'dpl'}) + .'
' + .'
' + .'' .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_headline() - .$lt{'asov'} + .''.$lt{'asov'}.'' .&Apache::lonhtmlcommon::row_closure(1) .&Apache::lonhtmlcommon::end_pick_box() .'' @@ -421,7 +501,10 @@ END .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_title($lt{'oaas'}) - .'' + .'' + .''.(' 'x2) + .''.', ' + .$lt{'sta'}.' '.$openallfrom.'' .&Apache::lonhtmlcommon::row_closure() .&Apache::lonhtmlcommon::row_headline() @@ -436,6 +519,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() @@ -468,7 +555,7 @@ END .'' .&Apache::lonhtmlcommon::row_closure() ); - if ($crstype eq 'Course') { + unless ($crstype eq 'Community') { $r->print(&Apache::lonhtmlcommon::row_headline() .'

'.$lt{'aens'}.'

' .&Apache::lonhtmlcommon::row_closure() @@ -531,7 +618,8 @@ END

-' + +

' ); } elsif ($crstype eq 'Community') { $r->print(' @@ -541,6 +629,14 @@ END

' ); + } elsif ($crstype eq 'Placement') { + $r->print(' +

+ + + +

' + ); } $r->print(''. $end_page); @@ -553,15 +649,20 @@ 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'}); if ($env{'form.phase'} eq 'coursetwo') { $crstype='Course'; $enrollstart=&Apache::lonhtmlcommon::get_date_from_form('startenroll'); $enrollend=&Apache::lonhtmlcommon::get_date_from_form('endenroll'); + } elsif ($env{'form.phase'} eq 'placementtwo') { + $crstype='Placement'; } $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; @@ -602,6 +703,7 @@ sub create_course { clonedomain => $env{'form.clonedomain'}, datemode => $env{'form.datemode'}, dateshift => $env{'form.dateshift'}, + tinyurls => $env{'form.tinyurls'}, crsid => $env{'form.crsid'}, curruser => $env{'user.name'}.':'.$env{'user.domain'}, crssections => $env{'form.crssections'}, @@ -620,15 +722,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{'textbookcredits'})) { + $args->{'defaultcredits'} = $env{'form.defaultcredits'}; + } + + if ($env{'form.uniquecode'}) { + $args->{'uniquecode'} = 1; + } + # # Verify data # @@ -657,13 +770,21 @@ sub create_course { ,$env{'form.course_home'}.&Apache::loncommon::end_page())); return; } - my ($courseid,$crsudom,$crsunum); - my ($success,$output) = + my ($courseid,$crsudom,$crsunum,$code); + my ($success,$output,$clonemsgref) = &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 (ref($clonemsgref) eq 'ARRAY') { + my $user_lh = &Apache::loncommon::user_lang($env{'user.name'},$env{'user.domain'}); + foreach my $item (@{$clonemsgref}) { + if (ref($item) eq 'HASH') { + $r->print(&mt($item->{mt},@{$item->{args}}).'
'."\n"); + } + } + } if ($success) { # # Make the requested user a course coordinator or group coordinator @@ -682,8 +803,15 @@ sub create_course { $r->print( '

'.&mt('Manage Access Keys').'

'); } - # Flush the course logs so reverse user roles immediately updated - &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('

'. @@ -692,15 +820,19 @@ 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'); + &Apache::loncommon::start_page('Create a New Course, Community or Placement Test'); my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Options','Create_Course',undef,'Create_Courses'); my $end_page = &Apache::loncommon::end_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', @@ -708,45 +840,54 @@ sub print_intro_page { { linktext => 'Create a single course', url => '/adm/createcourse?phase=courseone', - permission => 1, + permission => $permission->{'create'}, #help => '', - icon => 'ccrs.png', + icon => 'crsnew.png', linktitle => 'Create a new course by completing an online form.' }, { linktext => 'Create a single community', url => '/adm/createcourse?phase=groupone', - permission => $show_all_choices, + permission => $permission->{'create'} && $cancreate->{'Community'}, #help => '', - icon => 'ccrs.png', + icon => 'crsnew.png', linktitle => 'Create a new collaborative community by completing an online form.' }, { - linktext => 'Create courses/communities by uploading an attributes file', + linktext => 'Create a single placement test', + url => '/adm/createcourse?phase=placementone', + permission => $permission->{'create'} && $cancreate->{'Placement'}, + #help => '', + icon => 'crsnew.png', + linktitle => 'Create a new placement test by completing an online form.' + }, + { + linktext => 'Create courses/communities/placement tests by uploading an attributes file', url => '/adm/createcourse?phase=batchone', - permission => 1, + permission => $permission->{'create'}, help => 'Batch_Creation', - icon => 'ccrs.png', - linktitle => 'Upload an attributes file containing specifications for one or more courses or communities in XML format.' + icon => 'uplcrs.png', + linktitle => 'Upload an attributes file containing specifications for one or more courses, communities or placement tests in XML format.' }, ] }, { categorytitle => 'Course/Community Requests', items => [ { - linktext => 'Approve or reject requests', + linktext => $approve, url => '/adm/createcourse?phase=requestdisplay', permission => $show_all_choices, #help => '', - icon => 'ccrs.png', - linktitle => 'Display course and community creation requests submitted by authorized users, held pending approval by a Domain Coordinator.' + icon => 'rcrs.png', + linktitle => 'Display course, community creation and placement test requests submitted by authorized users, held pending approval by a Domain Coordinator.' }, { - linktext => 'Display official course requests', + linktext => 'View pending official course requests', url => '/adm/createcourse?phase=pendingdisplay', permission => $show_all_choices, #help => '', - icon => 'ccrs.png', + icon => 'edit-find.png', + alttext => '', linktitle => 'Display official course requests submitted by authorized users, held pending validation of instructor status.' }, ] @@ -759,7 +900,7 @@ sub print_intro_page { permission => $show_all_choices, #help => '', icon => 'document-properties.png', - linktitle => 'Display information about when, how and by whom courses and communities were created in this domain.' + linktitle => 'Display information about when, how and by whom courses, communities and placement tests were created in this domain.' }, ] }, @@ -776,60 +917,88 @@ sub print_intro_page { sub upload_batchfile { my $r = shift; my $start_page = - &Apache::loncommon::start_page('Create a New Course or Community'); - my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Community Attributes File','Create_Course',undef,'Create_Courses'); + &Apache::loncommon::start_page('Create a New Course, Community, or Placement Test'); + my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Upload Course/Community/Placement Test Attributes File','Create_Course',undef,'Create_Courses'); my $end_page = &Apache::loncommon::end_page(); $r->print($start_page.$crumbs); - $r->print('

'.&mt('Upload a courses or communities attributes file').'

'); + $r->print('

'.&mt('Upload a courses, communities or placement tests attributes file').'

'); $r->print('
'. ''. '

'. '
'); + 'value="'.&mt('Create Courses/Communities/Placement Tests').'" />'); $r->print($end_page); return; } 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,$clonemsg,$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,$clonemsg,$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); + } + if ($clonemsg) { + $clonemsg = '

'.$clonemsg.'

'."\n"; + } } + } 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.$clonemsg.$result.'
'. + &mt('Creation options menu').''. + &Apache::loncommon::end_page()); } @@ -914,6 +1083,8 @@ sub print_creation_logs { $crstype = '.'; } elsif ($curr{'type'} eq 'community') { $crstype = 'Community'; + } elsif ($curr{'type'} eq 'placement') { + $crstype = 'Placement'; } my ($instcodefilter,$regexpok); @@ -925,7 +1096,7 @@ sub print_creation_logs { if ($numtitles) { if (($curr{'type'} eq 'official') || ($curr{'type'} eq 'unofficial')) { $instcodefilter = &instcode_srchstr($dom,$numtitles); - &Apache::courseclassifier::instcode_search_str($dom,$numtitles); + &Apache::courseclassifier::instcode_search_str($dom,$numtitles,\@codetitles); if ($curr{'type'} eq 'official') { $regexpok = 1; } else { @@ -1004,6 +1175,8 @@ sub print_creation_logs { my $showtype; if ($courses{$cid}{type} eq 'Community') { $showtype = &mt('community'); + } elsif ($courses{$cid}{type} eq 'Placement') { + $showtype = &mt('placement test'); } else { my $instcode = $courses{$cid}{inst_code}; if ($instcode ne '') { @@ -1117,7 +1290,7 @@ sub creation_display_filter { $typename = $typenames->{$type}; } } - $output .= ''."\n"; + $output .= ''."\n"; } $output .= ''; } @@ -1204,6 +1377,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; @@ -1214,14 +1439,32 @@ 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, + Placement => 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; @@ -1232,9 +1475,12 @@ 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'})) || + (($env{'form.phase'} eq 'placementtwo') && + ($cancreate{'Placement'})))) { &Apache::lonhtmlcommon::add_breadcrumb ({href=>"/adm/createcourse?phase=$env{'form.prevphase'}", text=>&mt('[_1] Creation Settings',), @@ -1244,21 +1490,26 @@ 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'})) || + (($env{'form.phase'} eq 'placementone') && + ($cancreate{'Placement'})))) { &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", @@ -1275,12 +1526,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", @@ -1297,7 +1553,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'}).'
'. @@ -1309,12 +1565,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", @@ -1322,9 +1583,11 @@ 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::loncoursequeueadmin::process_official_reqs('domain',$env{'request.role.domain'}, + $env{'user.name'},$env{'user.domain'}). + ''. &Apache::loncommon::end_page()); } elsif (($env{'form.phase'} eq 'creationlog') && ($show_all_choices)) { &Apache::lonhtmlcommon::add_breadcrumb @@ -1336,12 +1599,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'}=